这里记录了一下 SpringBoot 1.5.X 升级到 SpringBoot 2.1.X 遇到的坑
配置类调整
配置匹配策略调整
原来的 驼峰 中横线 下划线 均改为 中横线识别 不然启动会报错 找不到变量
1.0
1
2
3
4
5eureka:
instance:
hostname: ${spring.cloud.client.ipAddress}
prefer-ip-address: true
instanceId: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}2.0
1
2
3
4
5eureka:
instance:
hostname: ${spring.cloud.client.ip-address}
prefer-ip-address: true
instanceId: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
配置
spring.http
调整到spring.servlet
1.0
1
2
3
4
5spring:
http:
multipart:
max-file-size: 30MB
max-request-size: 30MB2.0
1
2
3
4
5
6spring:
servlet:
multipart:
enabled: true
max-file-size: 30MB
max-request-size: 30MB
actuator 端点配置改变
1.0
1
2
3
4
5
6
7
8
9
10# 管理端点
management:
security:
enabled: false
#启用shutdown
endpoints:
shutdown:
enabled: true
#禁用密码验证
sensitive: false2.0
1
2
3
4
5
6
7
8
9
10
11# 管理端点
management:
endpoint:
shutdown:
# 开启 Shutdown 端点
enabled: true
endpoints:
web:
exposure:
# 开启所有端点
include: *
POM文件改变
Eureka 客户端POM改变
1.0
1
2
3
4
5
6
7
8<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>2.0
1
2
3
4
5
6
7
8<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Zuul POM 改变
1.0
1
2
3
4<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>2.0
1
2
3
4<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
Session POM 改变
1.0
1
2
3
4<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>2.0
1
2
3
4<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
Hystrix POM 改变
1.0
1
2
3
4<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>2.0
1
2
3
4<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
代码类变更
包名称修改
Rabbit 的相关包路径改变
1.0
1
2import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;2.0
1
2import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
Feigh 的 EnableFeignClients 包路径改变
1.0
1
import org.springframework.cloud.netflix.feign.EnableFeignClients;
2.0
1
import org.springframework.cloud.openfeign.EnableFeignClients;
代码类修改
Zuul FallbackProvider 改变
1.0
1
2
3
4
5
6
7
8
9
public ClientHttpResponse fallbackResponse() {
return new DefaultFallbackResponse();
}
public ClientHttpResponse fallbackResponse(Throwable cause) {
return new DefaultFallbackResponse();
}2.0
1
2
3
4
public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
return new DefaultFallbackResponse();
}
其他错误
启动错误
- 配置了
spring.datasource.type
导致的 删除即可1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:
Property: spring.datasource.type
Value: org.apache.tomcat.jdbc.pool.DataSource
Origin: "spring.datasource.type" from property source "bootstrapProperties"
Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]
Action:
Update your application's configuration