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 升级记录》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

众妙之门

众妙之门

Smashing Magazine / 腾讯ISUX社交用户体验设计部 / 人民邮电出版社 / 2013-4 / 59.00元

《众妙之门——网站重新设计之道》是一本精彩、实用的网站UI设计宝典,其中的文章来自于世界知名WEB设计与开发博客Smashing Magazine。全书内容丰富,包括:网站重新设计的商业思考,HTML5与CSS3,重新认识JavaScript,构建更优用户体验的技术,移 动用户体验设计,等等。这些都是目前业内热度最高、从业人员最想了解的话题。无论是设计师还是开发人员,无论水平是高还是低,读者都能从......一起来看看 《众妙之门》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

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

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试