java开发中错误记录汇总
json相关
1、在Apifox测试http请求,使用json格式的数据请求时,报错。
Resolved [org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error:
Unexpected character ('u' (code 117)):
was expecting double-quote to start field name;
nested exception is com.fasterxml.jackson.core.JsonParseException:
Unexpected character ('u' (code 117)):
was expecting double-quote to start field name<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 2, column: 2]]
json数据格式错误,key需要使用双引号。
https相关
1、访问https协议的请求时,报错。
sun.security.validator.ValidatorException:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
没有验证证书导致。解决方式,要么验证,要么忽略。
springboot
No adapter for handler
1、新建工程访问请求时出现。
javax.servlet.ServletException: No adapter for handler [com.spring.demo.web.GreetingController@3f37413a]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1302) ~[spring-webmvc-5.3.19.jar:5.3.19]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1050) ~[spring-webmvc-5.3.19.jar:5.3.19]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.19.jar:5.3.19]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.19.jar:5.3.19]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.19.jar:5.3.19]
没有HandlerAdapter适配器。原因是我的Controller没有正确配置RequestMapping。
‘RedisTemplate’ that could not be found.
2、集成redis,启动时报错如下:
Field redisTemplate in com.example.common.redis.RedisBean required a bean of type 'org.springframework.data.redis.core.RedisTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.data.redis.core.RedisTemplate' in your configuration.
解决办法:将@Autowired改为@Resource解决问题,经查二者区别如下:
- @Autowired默认按照byType方式进行bean匹配,@Resource默认按照byName方式进行bean匹配
- @Autowired是Spring的注解,@Resource是J2EE的注解
Invalid bound statement (not found)
mybatis集成报错:
Invalid bound statement (not found): com.soft.mapper.test.SysRoleMapper.selectRoleList
解决办法:
- 查询xml文件中namespace是否和mapper接口实际路径对应,经查一致;
- mapper接口方法和xml文件中的id是否一致,经查一致;
- 查看yml文件中mapperLocations配置项,经查mapperLocations配置为:classpath*:mapper/Mapper.xml,修改为classpath:mapper/**/*Mapper.xml,重启测试ok。