转载自   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 {@Overrideprotected 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 {@Overrideprotected 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 变成了学不动系列了。。。

Spring Cloud 升级最新 Finchley 版本,踩了所有的坑相关推荐

  1. 厉害了,Spring Cloud Alibaba 发布 GA 版本!

    小马哥 & Josh Long 喜欢写一首诗一般的代码,更喜欢和你共同 code review,英雄的相惜,犹如时间沉淀下来的对话,历久方弥新. 相见如故,@杭州. 4 月 18 日,Josh ...

  2. Spring Cloud 升级之路 - 2020.0.x - 1. 背景知识、需求描述与公共依赖

    1. 背景知识.需求描述与公共依赖 1.1. 背景知识 & 需求描述 Spring Cloud 官方文档说了,它是一个完整的微服务体系,用户可以通过使用 Spring Cloud 快速搭建一个 ...

  3. Spring Cloud升级之路 - Hoxton - 8. 修改实例级别的熔断为实例+方法级别

    实例级别的熔断带来的困扰 如之前系列(Spring Cloud升级之路 - Hoxton - 4. 使用Resilience4j实现实例级别的隔离与熔断)所述,我们实现了实例级别的熔断.但是在生产中发 ...

  4. Jenkins升级最新LTS版本2.150.x,页面本地化之后出现部分英文部分中文的解决办法

    Jenkins升级最新LTS版本2.150.x,页面本地化之后出现部分英文部分中文的解决办法 查看官方版本升级文档 下载并启用插件:localization-zh-cn-plugin 查看官方版本升级 ...

  5. 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 => ...

  6. Spring Cloud学习笔记(Hoxtonl版本)

    Spring Cloud 什么是微服务 提出者与时间: Martin Fowler ,Mar 2014 微服务架构是一种架构模式,它提倡单一应用程序划分成一组小的服务,服务之间互相协调,互相配合,为用 ...

  7. Spring Cloud Consul 之Greenwich版本全攻略

    转载请标明出处: http://blog.csdn.net/forezp/article/details/87273153 本文出自方志朋的博客 个人博客版:https://www.fangzhipe ...

  8. spring cloud 2020 改变了版本的命名规则

    前言 一直对spring cloud 的版本命名规则很诟病,之前的spring cloud 版本名是根据伦敦地铁站名称的英文名称并按照字母a-z进行排序.虽然知道了规则感觉还行,但是这种对非英语语言环 ...

  9. Spring Cloud升级之路 - Hoxton - 10. 网关重试带Body的请求Body丢失的问题

    带 Body 的重试 Body 丢失 之前我们的配置里面,只对 Get 请求针对 500 响应码重试,但是针对像 Post 这样的请求,只对那种根本还没到发送 Body 的阶段的异常(例如连接异常)这 ...

最新文章

  1. mysql windows 管道连接,科技常识:Windows Server 2016 MySQL数据库安装配置详细安装教程...
  2. 计算机多媒体理论知识,计算机多媒体技术07311.doc
  3. java.io包有哪些方法_java.io包下常用类及常用方法介绍
  4. Hibernate5-唯一查询和聚合查询
  5. 路径前面加/和不加/
  6. android第一次作业
  7. 推荐两个非常实用的,Python装饰器
  8. day18 15.自定义连接池
  9. 蓝桥杯历届试题----斐波那契(矩阵快速幂)
  10. oracle创建表空间、用户
  11. KVM Disk Cache简析
  12. rsync实时同步服务部署
  13. docker专题(2):docker常用管理命令(下)
  14. 栈的应用实例——平衡符号
  15. esp分区创建 linux_善用EFI系统分区ESP
  16. charles安卓抓包步骤详解
  17. 新手对vue中特殊的标签属性ref和key的理解
  18. PyTorch中 detach() 、detach_()和 data 的区别
  19. 苹果微信更新不了最新版本_微信更新7.0版本,为何优先给iOS用户体验?这是在歧视安卓?...
  20. Openshift架构理解v3.11

热门文章

  1. core java面试题_CoreJava基础面试题
  2. leetcode739. 每日温度
  3. com.mysql.cj.exceptions.InvalidConnectionAttributeException
  4. Leetcode周赛复盘——第 276 场力扣周赛
  5. word List 17
  6. 类欧几里得算法详细推导过程(附带模板)
  7. miller_rabin 模板
  8. CF750F. New Year and Finding Roots
  9. cf208E. Blood Cousins
  10. 牛客题霸 [买卖股票的最好时机] C++题解/答案