springboot1.5迁移到2.x出现的问题

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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值