spring项目如何升级mysql包_SpringBoot项目版本升级:从1.5.3升级到2.1.8版本

本文记录了SpringBoot项目从1.5.3升级到2.1.8版本的过程,包括更新parent版本号、修改yml配置(如应用名、上下文路径、文件上传、mysql连接、redis配置)以及解决升级过程中遇到的Druid和SpringSecurity异常。
摘要由CSDN通过智能技术生成

SpringBoot项目版本升级:从1.5.3升级到2.1.8版本

前言

简单记录一次本人在自己的SpringBoot项目project-template中,把1.5.3版本升级到2.1.8版本时升级的步骤,及遇到的问题。

提升parent版本号

更改pom文件中parent的版本号

org.springframework.boot

spring-boot-starter-parent

2.1.8.RELEASE

修改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版本即可

com.alibaba

druid-spring-boot-starter

1.1.10

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

完结,撒花。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值