创建博客过程中遇到的问题
运行时出现找不到MappingJacksonHttpMessageConverter的情况
[org.springframework.web.context.ContextLoader]Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0'
... ...
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'org.springframework.http.converter.json.MappingJacksonHttpMessageConverter#2aa148c0'
... ...
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
... ...
原因是Spring 3.x 和4.X处理JSON的一个类不一样,而这个东西又配置在xml文件中,所以编译时又无法发现
spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
1. 查找替换所有XML中名字
2. 同时加入最新的FastJackson依赖
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.8.5</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.5</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.8.5</version> </dependency>
注意看这里:
Spring 3.x 升级到Spring 4.x 注意事项和步骤,错误解决方法
MySql 数据库更新为8.0及以上后,对应的应用程序数据库链接驱动包也要更新为8.0版本。否则会报驱动异常。
需要注意以下几点:
1.最新驱动包Maven下载配置如下:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> </dependency>
2.JDBC配置表更新如下:
以前的版本:
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://xxx.xx.xx.xxx:3306/db?characterEncoding=utf-8 jdbc.username=root jdbc.password=admin
现在的版本:
jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://xxx.xx.xx.xxx:3306/db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8 jdbc.username=root jdbc.password=admin
其中jdbc.driver=com.mysql.cj.jdbc.Driver
与jdbc.url=jdbc:mysql://xxx.xx.xx.xxx:3306/db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
中的useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8
为新加入的东西。