博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录
阅读量:6912 次
发布时间:2019-06-27

本文共 2306 字,大约阅读时间需要 7 分钟。

节前没有新业务代码,正好Greenwich刚发布,于是开始为期四天的框架代码升级。

之前的版本是 spring boot 1.5.10 , spring cloud Edgware.SR3

依赖升级

  • 增加依赖管理插件 apply plugin: 'io.spring.dependency-management'
  • spring-cloud-starter-eureka → spring-cloud-starter-netflix-eureka-client
  • spring-cloud-starter-feign → spring-cloud-starter-openfeign
  • gradle版本要求4.4

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:

  • org.mockito.Matchers → org.mockito.ArgumentMatchers 注意build时的warning
  • Mock方法时请使用Mocikto.doReturn(...).when(...),不使用when(...).thenReturn(...),否则@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,所有注入使用时需要

    @AutowriedFooFeign fooFeign

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

转载地址:http://amfcl.baihongyu.com/

你可能感兴趣的文章
转:Java中的Clone()方法详解
查看>>
ping命令
查看>>
【转】PHP网站(nginx、php-fpm、mysql) 用户权限解析
查看>>
Spring Boot项目的打包和部署
查看>>
元素绝对居中终极办法兼容IE8
查看>>
weblogic 的应用 常见问题处理 db2 链接不上(转载)
查看>>
linux下的Shell编程(5)循环
查看>>
Switch 语句
查看>>
[PHP] 网盘搜索引擎-采集爬取百度网盘分享文件实现网盘搜索(二)
查看>>
二叉堆
查看>>
Java中的Enum的继承
查看>>
[Android]RecyclerView的简单演示样例
查看>>
怎样在Java中运行Hive命令或HiveQL
查看>>
使用enca进行字符集转码
查看>>
Ubuntu下安装Oracle JRE运行环境
查看>>
docker 标记和推送镜像
查看>>
Mapreduce实战:序列化与反序列化 int,int[],string[][]
查看>>
可执行文件格式elf和bin
查看>>
Android中获取当前位置的使用步骤
查看>>
CEF中JavaScript与C++交互
查看>>