对于工作中出现的异常,特做记载,帮助自己记忆,也希望可以帮助到其他遇到相同问题的人。
1.com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
解决方案:没有连接上数据库,看是否是数据库的配置有问题。
2.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'loginController' method
解决方案:在使用requestMapping对controller命名时,出现了相同命名,检查是否有相同命名,对其进行修改即可。
3.java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value
解决方案:这是在保存Cookie时,Cookie只支持ASCII字符,而且不能有逗号、分号和空白。需要在保存时,进行转化,使用URLEncoder.encode(value,"utf-8")进行保存,使用URLDecoder.decode(name,"utf-8")进行解密。
4.java.sql.SQLException:null,message,fromserver:"Host'134.98.1.198 ' is not allowed to connect to this MySQL server"
解决方案:这是在连接数据库时存在问题,需要修改数据中mysql库中的user表,即可。
4.java.lang.IllegalArgumentException: bound must be positive。今天一直报这个错误,发现是应为使用Random.nextInt方法中时,传入的数值为负数所以报错,改成传正整数就可以了。