Spring Cloud 升级最新 Finchley 版本,踩坑指南!
https://blog.csdn.net/youanyyou/article/details/81530240
Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级。
升级前 => 升级后
Spring Boot 1.5.x => Spring Boot 2.0.2
Spring Cloud Edgware SR4 => Spring Cloud Finchley.RELEASE
Eureka Server
Eureka Server 依赖更新
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
- 1
- 2
- 3
- 4
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
- 1
- 2
- 3
- 4
Eureka Client
因为配置中心需要作为服务注册到注册中心,所以需要升级 Eureka Client,其他依赖没有变动。
Eureka Client 依赖更新
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
- 1
- 2
- 3
- 4
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
- 1
- 2
- 3
- 4
Spring Cloud
注册中心里面的客户端实例IP显示不正确
因为 Spring Cloud 获取服务客户端 IP 地址配置变更了。
升级前:
${spring.cloud.client.ipAddress}
- 1
升级后:
${spring.cloud.client.ip-address}
- 1
Spring Security
一般注册中心、配置中心都会使用安全加密,就会依赖 spring-boot-starter-security 组件,升级后有几下两个问题。
1、用户名和密码无法登录
因为 Spring Security 的参数进行了变更。
升级前:
security:
user:
name:
password:
- 1
- 2
- 3
- 4
升级后:
spring:
security:
user:
name:
password:
- 1
- 2
- 3
- 4
- 5
2、注册中心没有注册实例
如图所示,没有注册实例,两个注册中心无法互相注册。

因为 Spring Security 默认开启了所有 CSRF 攻击防御,需要禁用 /eureka 的防御。
在 Application 入口类增加忽略配置:
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
super.configure(http);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
3、配置中心无法加解密
升级后发现访问配置中心无法读取到配置,也无法加解密配置信息,访问配置中心链接直接跳转到了登录页面。

现在想变回之前的 basic auth 认证方式,找源码发现是自动配置跳到了登录页面,现在重写一下。
自动配置源码:
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)
protected void configure(HttpSecurity http) throws Exception {
logger.debug("Using default configure(HttpSecurity). If subclassed this will potentially override subclass configure(HttpSecurity).");
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().and()
.httpBasic();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
重写之后:
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/**").and().authorizeRequests().anyRequest()
.authenticated().and().httpBasic();
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
其实就是把 formLogin() 干掉了,又回到之前的 basic auth 认证方式,如下图所示。

现在我们又可以使用以下命令加解密了。
如解密:
curl http://xx.xx.xx.xx:7100/decrypt -d secret -u user:password
恢复 basic auth 之后,之前的服务需要加密连接配置中心的又正常运行了。
Maven
升级到 Spring Boot 2.x 之后发现 Spring Boot 的 Maven 启动插件不好用了,主要是 Profile 不能自由切换。
升级前:
spring-boot:run -Drun.profiles=profile1
- 1
升级后:
spring-boot:run -Dspring-boot.run.profiles=profile1
- 1
具体的请参考:
https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html
总结
以上都是踩完所有的坑总结出来的解决方案,实际解决问题的过程远要复杂的多。版本变化有点大,本次已成功升级了 Spring Cloud 基础依赖,及注册中心(Eureka Server)、配置中心(Config Server)。
其他像 Gateway 代替了 Zuul, 及其他组件再慢慢升级,Spring Cloud 的快速发展令升级变得非常蛋疼,本文记录了升级过程中踩过的所有的坑。。。
坑死了,已经保证编译、运行正常,其他还有什么坑不知道,刚升级完 Finchley 这个正式版本,Spring Cloud 刚刚又发布了 Finchley.SR1,感觉 Spring Cloud 变成了学不动系列了。。。
@ All 码农们:你们升级了吗?有遇到什么样的坑?欢迎留言!
Spring Cloud 升级最新 Finchley 版本,踩坑指南!的更多相关文章
- Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级. 升级前 ...
- Spring Cloud 升级最新 Greenwich 版本,舒服了~
去年将 Spring Cloud 升级到了 Finchley 版本: Spring Cloud 升级最新 Finchley 版本,踩了所有的坑! 这个大版本栈长是踩了非常多的坑啊,帮助了不少小伙伴. ...
- 【Finchley】【升级变更】Spring Cloud 升级到Finchley版本后需要注意的地方
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级. 升级前 ...
- Spark 1.6升级2.x防踩坑指南
原创文章,谢绝转载 Spark 2.x自2.0.0发布到目前的2.2.0已经有一年多的时间了,2.x宣称有诸多的性能改进,相信不少使用Spark的同学还停留在1.6.x或者更低的版本上,没有升级到2. ...
- spring cloud: 升级到spring boot 2.x/Finchley.RELEASE遇到的坑
spring boot2.x已经出来好一阵了,而且spring cloud 的最新Release版本Finchley.RELEASE,默认集成的就是spring boot 2.x,这几天将一个旧项目尝 ...
- 厉害了,Spring Cloud Alibaba 发布 GA 版本!
? 小马哥 & Josh Long ? 喜欢写一首诗一般的代码,更喜欢和你共同 code review,英雄的相惜,犹如时间沉淀下来的对话,历久方弥新. 相见如故,@杭州. 4 月 18 日, ...
- Spring Cloud 升级之路 - 2020.0.x - 1. 背景知识、需求描述与公共依赖
1. 背景知识.需求描述与公共依赖 1.1. 背景知识 & 需求描述 Spring Cloud 官方文档说了,它是一个完整的微服务体系,用户可以通过使用 Spring Cloud 快速搭建一个 ...
- Spring WebSocket踩坑指南
Spring WebSocket踩坑指南 本次公司项目中需要在后台与安卓App间建立一个长连接,这里采用了Spring的WebSocket,协议为Stomp. 关于Stomp协议这里就不多介绍了,网上 ...
- MySQL切换版本踩坑记录(包括恢复数据方法)
踩坑起因:在创建数据库时, 字段:create_time datetime DEFAULT CURRENT_TIMESTAMP, 报异常--Error Code: 1067 - Invalid def ...
随机推荐
- (转)轻松掌握shell编程中数组的常见用法及示例
缘起:在老男孩进行linux培训shell编程教学中,发现不少水平不错的网友及同学对数组仍然很迷糊,下面就给大家分享下数组的用法小例子,希望能给大家一点帮助.其实SHELL的数组很简单,好用.我们学习 ...
- winscp介绍与使用
winscp介绍 WinSCP 是一个 Windows 环境下使用的 SSH 的开源图形化 SFTP 客户端.同时支持 SCP 协议.它的主要功能是在本地与远程计算机间安全地复制文件,并且可以直接编辑 ...
- Js获取移动设备分辨率
在<head>中引入 <meta name="viewport" content="width=device-width, initial-scale ...
- Homemade Script Language: RED
Made by C, named after RED(RecovEr from SaDness) 欢迎批评 :)
- 【转载】CSS3 常用四个动画(旋转、放大、旋转放大、移动)
http://blog.csdn.net/fungleo/article/details/49848905
- php 设置虚拟目录
php 设置虚拟目录两个步骤,很简单. 第一,打开安装apache目录下的conf下面的httpd.conf文件. 找到IfModule 标记, 再它下面添加红色方框中的内容.注意不能少东西. ...
- 将webservice嵌套到以完成的web项目中
一.先把webservice服务端写入项目(基于spring) 1.在pom.xml中引入WebService相关的jar依赖 <!--webservice开始 --> <!--ht ...
- >>我要做特工系列 之 CSS 3_animation_向右滑出后下滑并停止
新手入门还没有正式发点啥东西,都是在装潢博客这个家了,到现在为止还是没有装修好..熟悉了这边的发布规范之后会持续在这里记录,给自己留下学习的脚印~ 这正式的第一篇随笔写个使用css3的动画效果. 总感 ...
- Promise对象(异步编程)
Promise对象解决函数的异步调用(跟回调函数一样) 三种状态: 未完成(pending)已完成(fulfilled)失败(rejected) 通过then函数来链式调用 目前市面上流行的一些类库:
- u-boot分析(三)---boot命令实现以及内核的启动
上片博文总结出了u-boot的工作流程,今天我们来分析,u-boot的两个比较重要的内容 1. U-boot命令的实现 2. U-boot如何启动内核 l 命令实现 我们 ...