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>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Eureka Client
因为配置中心需要作为服务注册到注册中心,所以需要升级 Eureka Client,其他依赖没有变动。
Eureka Client 依赖更新
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
Spring Cloud
注册中心里面的客户端实例IP显示不正确
因为 Spring Cloud 获取服务客户端 IP 地址配置变更了。
升级前:
${spring.cloud.client.ipAddress}
升级后:
${spring.cloud.client.ip-address}
Spring Security
一般注册中心、配置中心都会使用安全加密,就会依赖 spring-boot-starter-security
组件,升级后有几下两个问题。
1、用户名和密码无法登录
因为 Spring Security 的参数进行了变更。
升级前:
security:
user:
name:
password:
升级后:
spring:
security:
user:
name:
password:
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);
}
}
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();
}
重写之后:
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/**").and().authorizeRequests().anyRequest()
.authenticated().and().httpBasic();
}
}
其实就是把 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
升级后:
spring-boot:run -Dspring-boot.run.profiles=profile1
具体的请参考:
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 码农们:你们升级了吗?有遇到什么样的坑?欢迎留言!
转自:https://www.cnblogs.com/javastack/p/9446837.html
Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!的更多相关文章
- Spring Cloud 升级最新 Finchley 版本,踩坑指南!
https://blog.csdn.net/youanyyou/article/details/81530240 Spring Cloud 升级最新 Finchley 版本,踩了所有的坑! 2018年 ...
- Spring Cloud 升级最新 Greenwich 版本,舒服了~
去年将 Spring Cloud 升级到了 Finchley 版本: Spring Cloud 升级最新 Finchley 版本,踩了所有的坑! 这个大版本栈长是踩了非常多的坑啊,帮助了不少小伙伴. ...
- 【Finchley】【升级变更】Spring Cloud 升级到Finchley版本后需要注意的地方
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级. 升级前 ...
- 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 快速搭建一个 ...
- 001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点
一.前提 升级前 => 升级后 Spring Boot 1.5.x => Spring Boot 2.0.4.RELEASE Spring Cloud Edgware SR3 => ...
- Spring Cloud 升级之路 - 2020.0.x - 4. 使用 Eureka 作为注册中心
Eureka 目前的状态:Eureka 目前 1.x 版本还在更新,但是应该不会更新新的功能了,只是对现有功能进行维护,升级并兼容所需的依赖. Eureka 2.x 已经胎死腹中了.但是,这也不代表 ...
- spring cloud 版本号与 boot版本之间的对应关系(版本不对,会导致pom无法引入)
版本号规则 Spring Cloud并没有熟悉的数字版本号,而是对应一个开发代号. 开发代号看似没有什么规律,但实际上首字母是有顺序的,比如:Dalston版本,我们可以简称 D 版本,对应的 Edg ...
随机推荐
- CDI services--Decorators(装饰器)
1.Decorators装饰器综述 拦截器是一种强大的方法在应用程序捕捉运行方法和解耦.拦截器可以拦截任何java类型的调用. 这使得拦截器适合解决事务管理,安全性,以及日记记录. 本质上说,拦截器并 ...
- PHP----------一群猴子排成一圈,按1,2,...,n依次编号。
1.一群猴子排成一圈,按1,2,...,n依次编号.然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去...,如此不停的进行下去, 直到最后只剩下一只猴子为止,那 ...
- c++ 单元测试框架 gmock 深度剖析
c++ 单元测试框架 gmock 深度剖析 随着微服务和CI的流行,在目前的软件工程领域中单元测试可以说是必不可少的一个环节,在TDD中,单元测试更是被提高到了一个新的高度.但是很多公司由于很多不同的 ...
- PHP 程序员危机(转载)
感谢有这样的机会,能和大家一起来聊聊开发者的那些事儿. 其实程序员危机是一个真实存在的问题.也有人说是互联网行业的下滑或者互联网行业已过了风口等等.我在这儿主要谈的是 PHP 程序员的危机,而这种危机 ...
- XiangBai——【CVPR2018】Multi-Oriented Scene Text Detection via Corner Localization and Region Segmentation
XiangBai——[CVPR2018]Multi-Oriented Scene Text Detection via Corner Localization and Region Segmentat ...
- 用Nuget部署程序包
用Nuget部署程序包 Nuget是.NET程序包管理工具(类似linux下的npm等),程序员可直接用简单的命令行(或VS)下载包.好处: (1)避免类库版本不一致带来的问题.GitHub是管理源代 ...
- 【DOM练习】淘宝购物车
HTML: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...
- Windows环境下IOS APP打包上传AppStore详细流程
我们知道在上架苹果应用过程中,申请发布证书需要用到钥匙串,上传ipa需要用到xcode或Application loader提交构建版本,这都需要Mac苹果机. 本文介绍如何在Windows环境下申请 ...
- decimal(19,6)什么意思
decimal(19,6)什么意思 数字长度19位,精确到小数点后6位例如0.123456 mysql中varchar(50)最多能存多少个汉字 首先要确定mysql版本4.0版本以下,varchar ...
- HTML5 本地缓存 window.localStorage
简单运用 html <div onclick="storage('invoice')"></div> js 设置 与 获取 function storag ...