springboot1.5.9升级到springboot2.1.3遇到的问题

原文链接:https://www.lskyf.com/post/112

1.问题描述:

Failed to bind properties under 'spring.datasource.druid.driver' to java.sql.Driver:
    Property: spring.datasource.druid.driver
    Value: com.mysql.jdbc.Driver
    Origin: class path resource [application.yml]:5:20
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.sql.Driver]

解决方法 

修改application.yml文件将老版本的
spring:
  datasource:
  driver: com.mysql.jdbc.Driver
修改为
spring:
  datasource:
    druid:
      driver-class-name: com.mysql.jdbc.Driver
 

2.RabbitMq报错

The bean 'messageConverter', defined in class path resource [com/wanshifu/customer/boot/starter/rabbit/RabbitAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [cn/xy/wanc/sysm/core/config/RabbitConfig.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

解决方法 
添加
spring.main.allow-bean-definition-overriding=true

3.过时的property配置

Deprecated configuration property 'spring.http.multipart.maxFileSize'
Deprecated configuration property 'spring.http.multipart.max-request-size' 

spring.servlet.multipart.maxFileSize=10Mb
spring.servlet.multipart.maxRequestSize=1000Mb

解决方法 

修改为
spring.servlet.multipart.maxFileSize=10
spring.servlet.multipart.maxRequestSize=1000

 

server.context-path=/web

修改为

server.servlet.context-path=/web

4.WebMvcConfigurerAdapter过时


WebMvcConfigurerAdapter过时导致之前的代码HandlerInterceptor拦截了static静态资源
解决方法:将之前extends WebMvcConfigurerAdapter修改为implements  WebMvcConfigurer

@Configuration
public class MyWebAppConfigurer  implements WebMvcConfigurer{
   String[]excludes=new String[]{
            "/static/**",//排除静态文件被拦截
            "/wxuser/login"//其他不拦截的请求
    };

   public void addInterceptors(InterceptorRegistry registry){
       registry.addInterceptor(WXLoginInterceptor()).addPathPatterns("/**").excludePathPatterns(excludes);
   }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      //排除静态资源
      registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
  }
}

5.Error:(4, 40) java: 程序包com.fasterxml.jackson.annotation不存在

 
            com.fasterxml.jackson.core
            jackson-databind
       

6.Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure] from ClassLoader [sun.misc.Launcher$AppClassLoader@18

将druid升级到1.1.10

 

7.上传图片的controller方法不执行

我遇到的一种原因图片过大。

解决方法:

1.前端压缩图片

2.服务器将参数配置放大

3.新版本对图片上传配置做了调整需要带单位(新版本默认maxFileSize=1M)超过controller就无法接收到请求

以前properties是

##图片上传限制20兆
spring.servlet.multipart.maxFileSize=2
spring.servlet.multipart.maxRequestSize=10

现在需要加上单位

##图片上传限制20兆
spring.servlet.multipart.maxFileSize=20M
spring.servlet.multipart.maxRequestSize=200M

 

 

你可能感兴趣的:(spring-boot,spring-boot2.x,Spring,Boot系列)