1. 程式人生 > >SpringBoot專案版本升級:從1.5.3升級到2.1.8版本

SpringBoot專案版本升級:從1.5.3升級到2.1.8版本

SpringBoot專案版本升級:從1.5.3升級到2.1.8版本

前言

簡單記錄一次本人在自己的SpringBoot專案project-template中,把1.5.3版本升級到2.1.8版本時升級的步驟,及遇到的問題。

提升parent版本號

更改pom檔案中parent的版本號

   <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.1.8.RELEASE</version>
       <relativePath />
   </parent>

修改yml檔案中的部分配置

在1.5版本中,部分配置與2.1版本有些不同

應用名及上下文

1.5版本

server:
  application-display-name: ProjectTemplate-Web
  context-path: /project

2.1版本

server:
  servlet:
    application-display-name: ProjectTemplate-Web
    context-path: /project

檔案上傳

1.5版本

spring:
  http:
    multipart:
      location: E:/dev/Project/work/project_data/projettemplate/temp/dev  #檔案臨時目錄
      max-request-size: 40MB
      max-file-size: 40MB

2.1版本

 spring:
   servlet:
     multipart:
       location: E:/dev/Project/work/project_data/projettemplate/temp/dev # 檔案臨時目錄
       max-request-size: 40MB
       max-file-size: 40MB

mysql連線

1.5版本

  spring:
     datasource:  
       url: jdbc:mysql://localhost:3306/projettemplate?useUnicode=true&useSSL=false&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT
       username: root
       password: root
       type: com.alibaba.druid.pool.DruidDataSource
       driver-class-name: com.mysql.cj.jdbc.Driver

2.1版本

  spring:
     datasource:  
       druid:
         url: jdbc:mysql://localhost:3306/projettemplate?useUnicode=true&useSSL=false&characterEncoding=utf-8&autoReconnect=true&serverTimezone=GMT
         username: root
         password: root
         db-type: com.alibaba.druid.pool.DruidDataSource
         driver-class-name: com.mysql.cj.jdbc.Driver

redis配置

1.5版本

 spring:
  redis:   # REDIS (RedisProperties)
    database: 0
    host: 127.0.0.1
    port: 6379
    timeout: 2000
    pool:
      max-active: 8
      max-wait: -1
      max-idle: 8
      min-idle: 0

2.1版本

 spring:
   redis:   # REDIS (RedisProperties)
     database: 0
     host: 127.0.0.1
     port: 6379
     timeout: 2000
     jedis:
       pool:
         max-idle: 8
         max-wait: -1

啟動專案遇到的問題

druid-spring-boot-starter版本過低報異常

當版本為1.1.6時,報異常:

... ...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
... ...
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvider
... ... 
java.lang.IllegalStateException: Failed to introspect Class [com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
... ... 
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/autoconfigure/jdbc/metadata/DataSourcePoolMetadataProvider
... ... 
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider

升級為1.1.10版本即可

 <dependency>
     <groupId>com.alibaba</groupId>
     <artifactId>druid-spring-boot-starter</artifactId>
     <version>1.1.10</version>
 </dependency>

SpringSecurity的AuthenticationManager啟動報異常

當報異常:

A component required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found

在SpringSecurity檔案中重寫即可

    @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

其他

當報以下異常:

The bean 'userDetailsServiceImpl', defined in class path resource [com/itmacy/dev/auth/security/SecurityConfig.class], could not be registered. A bean with that name has already been defined in file [/Users/chenmeixuan/macy/dev/project/study/webBack/project-template/target/project-template-1.0.0-SNAPSHOT_20200215-1336/classes/com/itmacy/dev/auth/security/UserDetailsServiceImpl.class] and overriding is disabled.

在yml檔案中新增以下配置即可

spring:
   main:
     allow-bean-definition-overriding: true

完結,撒花。。