后端开发错误总结


错误1

  • 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported
  • 错误原因:没有接收到前端传入的参数,修改为如下
  • 参考

错误2

  • 错误还原:使用log.info();时报错cannot resolve symbol 'log'
  • 错误原因:idea没有安装Lombok插件、项目没有导入Lombok依赖、类中没有添加注解@Slf4j

错误3

  • 启动项目时报错如下
2021-12-03 13:33:33.927 ERROR 7228 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:564)

The following method did not exist:

    org.apache.ibatis.session.Configuration.setDefaultEnumTypeHandler(Ljava/lang/Class;)V

The method's class, org.apache.ibatis.session.Configuration, is available from the following locations:

    jar:file:/C:/repo/maven/org/mybatis/mybatis/3.4.4/mybatis-3.4.4.jar!/org/apache/ibatis/session/Configuration.class

The class hierarchy was loaded from the following locations:

    org.apache.ibatis.session.Configuration: file:/C:/repo/maven/org/mybatis/mybatis/3.4.4/mybatis-3.4.4.jar
  • 错误原因:如下代码生成器依赖mybatis依赖冲突
  
      org.mybatis
      mybatis
      3.4.4
  
  
  
      org.mybatis.generator
      mybatis-generator-core
      1.3.5
  
————————————————————————————————————————————————————
  
      org.mybatis.spring.boot
      mybatis-spring-boot-starter
      1.3.2
  
  
      com.alibaba
      druid-spring-boot-starter
      1.1.10
  

错误4

  • 服务消费者模块assess通过openFeign调用服务提供者模块hires
  • 如下为服务提供者模块hires的控制层接口
@RestController
@RequestMapping("/hires")
public class FeignController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
    public RespResult getUserinfo(@RequestParam(value = "id") int id){
        User userInfo = userService.getUserInfo(id);
        return RespResult.success(userInfo);
    }

}

  • 如下为服务消费者模块assess的service层
@Component
@FeignClient(value = "hires-8081")
public interface UserFeignService {

    @RequestMapping(value = "/hires/getInfo", method = RequestMethod.GET)
    public RespResult getUserinfo(@RequestParam(value = "id") int id);

}

  • 以下为服务消费者模块assess的控制层
@RestController
@Slf4j
public class UserFeignController {
    @Resource
    private UserFeignService userFeignService;

    @RequestMapping(value = "/hi", method = RequestMethod.GET)
    public RespResult getUserinfo(@RequestParam(value = "id") int id){
        return userFeignService.getUserinfo(id);
    }

}

  • 错误还原:通过服务消费者模块assess-8082调用hires-8081时报错status 405 reading EmpService#findAll(Integer);
  • 错误原因:在调用方法时应使用@RequestParam(value = "id")注入参数
  • 参考

错误5

  • 错误描述:当某个bean注入到另一个类中时,IDE提示没有注入
  • 解决方案:在IDEA中 点击 File → Invalidate Caches/Restart,清理了缓存重启IDEA
  • 参考

错误6

  • 错误还原:使用maven打包项目时报错如下
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project helloworld: Input length = 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

  • 解决方案:配置pom.xml中的maven插件

    org.springframework.boot
    spring-boot-maven-plugin


    org.apache.maven.plugins
    maven-resources-plugin
    3.1.0


  • 参考

错误7

  • 错误还原:启动项目后控制台打印:org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 1
  • 解决方案:将IDE的编码格式改为UTF-8
  • 参考

错误8

  • gradle项目打包时报错
  • 解决方案:删除报错字符

错误9

  • 在cloudalibaba + security项目中配置nacos报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name
  • 解决方案:注释掉management
spring:
  cloud:
    nacos:
      discovery:
        server-addr: 192.168.43.150:8848 
management:
  endpoints:
    web:
      exposure:
        include: '*'