【Finchley】【升级变更】Spring Cloud 升级到Finchley版本后需要注意的地方
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级。
升级前 => 升级后
Spring Boot 1.5.4 => Spring Boot 2.0.5
Spring Cloud Dalston SR1 => Spring Cloud Finchley.SR1
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(要连接注册中心的项目)
升级前:
<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>
Feign
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
Ribbon
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
Hystrix
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
Zuul
升级前:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
升级后:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</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
【Finchley】【升级变更】Spring Cloud 升级到Finchley版本后需要注意的地方的更多相关文章
- Spring Cloud 升级最新 Finchley 版本,踩了所有的坑!
Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Boot 2.x 的 Finchley 版本,现在一起为项目做一次整体框架升级. 升级前 ...
- Spring Cloud 升级最新 Finchley 版本,踩坑指南!
https://blog.csdn.net/youanyyou/article/details/81530240 Spring Cloud 升级最新 Finchley 版本,踩了所有的坑! 2018年 ...
- spring cloud: 升级到spring boot 2.x/Finchley.RELEASE遇到的坑
spring boot2.x已经出来好一阵了,而且spring cloud 的最新Release版本Finchley.RELEASE,默认集成的就是spring boot 2.x,这几天将一个旧项目尝 ...
- Spring Cloud 升级最新 Greenwich 版本,舒服了~
去年将 Spring Cloud 升级到了 Finchley 版本: Spring Cloud 升级最新 Finchley 版本,踩了所有的坑! 这个大版本栈长是踩了非常多的坑啊,帮助了不少小伙伴. ...
- Spring Cloud 升级之路 - 2020.0.x - 1. 背景知识、需求描述与公共依赖
1. 背景知识.需求描述与公共依赖 1.1. 背景知识 & 需求描述 Spring Cloud 官方文档说了,它是一个完整的微服务体系,用户可以通过使用 Spring Cloud 快速搭建一个 ...
- 厉害了,Spring Cloud Alibaba 发布 GA 版本!
? 小马哥 & Josh Long ? 喜欢写一首诗一般的代码,更喜欢和你共同 code review,英雄的相惜,犹如时间沉淀下来的对话,历久方弥新. 相见如故,@杭州. 4 月 18 日, ...
- Spring Cloud 升级之路 - 2020.0.x - 4. 使用 Eureka 作为注册中心
Eureka 目前的状态:Eureka 目前 1.x 版本还在更新,但是应该不会更新新的功能了,只是对现有功能进行维护,升级并兼容所需的依赖. Eureka 2.x 已经胎死腹中了.但是,这也不代表 ...
- Spring Cloud 升级之路 - 2020.0.x - 6. 使用 Spring Cloud LoadBalancer (1)
本项目代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 我们使用 Spri ...
- Spring Cloud 升级之路 - 2020.0.x - 3. Undertow 的 accesslog 配置
上一节我们讲述了如何使用 Undertow 作为我们的 Web 服务容器,本小节我们来分析使用 Undertow 的另一个问题,也就是如何配置 accesslog,以及 accesslog 的各种占位 ...
随机推荐
- 谈谈html中一些比较"偏门"的知识(map&area;iframe;label)
说明:这里所说的"偏门"只是相对于本人而言,记录在此,加深印象.也希望有需要的朋友能获得些许收获! 1.空元素(void):没有内容的元素. 常见的有:<br>,< ...
- D Tree Requests dfs+二分 D Pig and Palindromes -dp
D time limit per test 2 seconds memory limit per test 256 megabytes input standard input output stan ...
- Qt & VS2013 报错:There's no Qt version assigned to this project for platform Win32
如果你想了解关于Qt与VS2013开发环境搭建,可以至此翻页. 这里主要分享环境已搭建成功,在构建项目时遇到的报错解决方案. [1]Qt 与 VS2013开发环境构建时报错 报错界面如下: 注意:对话 ...
- 开源数据流管道-Luigi vs Azkaban vs Oozie vs Airflow
原文链接:https://www.jianshu.com/p/4ae1faea733b 随着企业的发展,他们的工作流程变得更加复杂,越来越多的有着错综复杂依赖关系的工作流需要增加监控,故障排除.如果没 ...
- 实现Winform 跨线程安全访问UI控件
在多线程操作WinForm窗体上的控件时,出现“线程间操作无效:从不是创建控件XXXX的线程访问它”,那是因为默认情况下,在Windows应用程序中,.NET Framework不允许在一个线程中直接 ...
- win10 +python3.6环境下安装opencv以及pycharm导入cv2有问题的解决办法
一.安装opencv 借鉴的这篇博客已经写得很清楚了--------https://blog.csdn.net/u011321546/article/details/79499598 ,这 ...
- jdbc连接 orale 和 mysql 所需要的jar包
oracle: ojdbc6-12.1.0.2.jar mysql: mysql-connector-java-5.1.47.jar
- 小纪a
感觉挺好的两段代码:虽然已经存在,但是这是我自己敲出来的,没有照抄,真心话,所以记录下来. 1.菱形代码: #include <stdio.h>void main() { int i, j ...
- ==和equasl、hashmap原理(***)
public class String01 { public static void main(String[] args) { String a="test"; String b ...
- Django中Session
Django中默认支持Session,其内部提供了5种类型的Session供开发者使用: ·数据库(默认) ·缓存 ·文件 ·缓存+数据库 ·加密cookie (1)数据库中的Session Djan ...