springboot1.5迁移到2.x出现的问题
恩…我的很神奇,暂时迁移的时候只有启动类报错,所以这里就先把启动类的修改成分贴出来吧,
这些都是借鉴网上的一个大神的,自己总结的:
1.启动类要继承一下****SpringBootServletInitializer
@SpringBootApplication @MapperScan("com.lssti.api.dao")
public class LishengApiApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(LishengApiApplication.class, args); }
2.数据源也要进行修改,要把时区加上
**
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true
spring.datasource.username=root
spring.datasource.password=123456
3.如果不使用spring的jackjson,想用fastjson的话,自己配置bean的时候需要注意继承的是WebMvcConfigurer
说是之前的失效了,配置bean的内容也是借鉴的网上的大神的,具体是谁也忘了,
//将一个物理类变成一个配置文件
@Configuration
//适配器
public class MyWebMvcConfigurerAdapter implements WebMvcConfigurer {
/**
* 利用fastjson替换掉jackson,且解决中文乱码问题
* @param converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//1.构建了一个HttpMessageConverter FastJson 消息转换器
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//2.定义一个配置,设置编码方式,和格式化的形式
FastJsonConfig fastJsonConfig = new FastJsonConfig();
//3.设置成了PrettyFormat格式
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//4.处理中文乱码问题
List<MediaType> fastMediaTypes = new ArrayList<>();
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
fastConverter.setSupportedMediaTypes(fastMediaTypes);
//5.将fastJsonConfig加到消息转换器中
fastConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastConverter);
}
}