Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录
source link: https://segmentfault.com/a/1190000018094154?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
节前没有新业务代码,正好Greenwich刚发布,于是开始为期四天的框架代码升级。
之前的版本是 spring boot 1.5.10 , spring cloud Edgware.SR3
依赖升级
apply plugin: 'io.spring.dependency-management'
boot : spring-boot-starter-data-jpa
- delete → deleteById
-
findone → findById
这个改动确实大,返回值变成了Optional,合理是合理的,只改的真多。。
boot : spring-boot-starter-data-redis
Jedis → Lettuce
还好并没有使用它的autoconfiguration,配置上有一个小坑,Jedis的redis.timeout是表示connection timeout, 而Lettuce是表示command timeout,之前配置成0的,如果set到Lettuce的commandtimeout里面那就要抛异常了。
配置:
可以在build.gradle中加入,启动时会检查配置是否兼容
compile "org.springframework.boot:spring-boot-properties-migrator"
注意:完成迁移后需要删除
警告如上图会告知最新的配置格式
boot: spring-boot-starter-actuator
endpoint的暴露方式变化, management.endpoints.web.exposure.include = "*"
表示暴露所有endpoints,如果配置了security那么也需要在security的配置中开放访问 /actuator
路径
boot: spring-boot-starter-security
自动注入的 AuthenticationManager
可能会找不到
If you want to expose Spring Security’s AuthenticationManager
as a bean, override the authenticationManagerBean
method on your WebSecurityConfigurerAdapter
and annotate it with @Bean
.
cloud : eureka
各个项目在注册中心里面的客户端实例IP显示不正确,需要修改每个项目的
bootstarp.yml
- ${spring.cloud.client.ipAddress} → ${spring.cloud.client.ip-address}
boot: spring-boot-starter-test:
@spybean
其他问题
- 版本升级后会有deprecated的类或方法,所以要注意看console中build的warning信息
-
由于spring cloud依赖管理插件强制cuator升级到4.0.1,导致我们使用的elestic-job不能正常工作,只能强行控制版本。
dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${SPRING_CLOUD_VERSION}" } dependencies { dependency 'org.apache.curator:curator-framework:2.10.0' dependency 'org.apache.curator:curator-recipes:2.10.0' dependency 'org.apache.curator:curator-client:2.10.0' } }
-
如果启用出现error,报bean重复,首先确认是不是故意覆盖,如重写spring-boot自带的bean,如是,可以在bootstrap.yml加入
spring.main.allow-bean-definition-overriding=true
-
FeignClient注解增加了contextId属性
@FeignClient(value = "foo", contextId = "fooFeign")
此contextId即表示bean id,所有注入使用时需要
@Autowried FooFeign fooFeign
如果不写contextId,当多个class都是@FeignClient("foo"),即会认为是同一个bean而排除上一条所说的warning
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK