Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录

栏目: Java · 发布时间: 6年前

内容简介:节前没有新业务代码,正好Greenwich刚发布,于是开始为期四天的框架代码升级。之前的版本是 spring boot 1.5.10 , spring cloud Edgware.SR3Jedis → Lettuce

节前没有新业务代码,正好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"

注意:完成迁移后需要删除

Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录

警告如上图会告知最新的配置格式

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

其他问题

  1. 版本升级后会有deprecated的类或方法,所以要注意看console中build的warning信息
  2. 由于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'
        }
    }
  3. 如果启用出现error,报bean重复,首先确认是不是故意覆盖,如重写spring-boot自带的bean,如是,可以在bootstrap.yml加入

    spring.main.allow-bean-definition-overriding=true
  4. FeignClient注解增加了contextId属性

    @FeignClient(value = "foo", contextId = "fooFeign")

    此contextId即表示bean id,所有注入使用时需要

    @Autowried
    FooFeign fooFeign

    如果不写contextId,当多个class都是@FeignClient("foo"),即会认为是同一个bean而排除上一条所说的warning


以上所述就是小编给大家介绍的《Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

未来版图

未来版图

麻省理工科技评论 / 人民邮电出版社 / 2018-5-1 / CNY 69.80

《麻省理工科技评论》作为世界上历史悠久、影响力极大的技术商业类杂志,每年都会依据公司的科技领军能力和商业敏感度这两个必要条件,从全球范围内选取50家未来可能会成为行业主导的聪明公司。 这些聪明公司,并非都是行业巨头,甚至专利数量、公司所在地以及资金规模都不在考察范围内。 这些公司是“高精尖科技创新”与“能够保证公司利益* 大化的商业模式”的完 美融合。无论公办私营,无关规模大小,这些遍布全球......一起来看看 《未来版图》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换