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 Finchley.SR1
1.1、Eureka Server
ureka 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>
1.2、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>
1.3、Spring Cloud
注册中心里面的客户端实例IP显示不正确
因为 Spring Cloud 获取服务客户端 IP 地址配置变更了。
升级前:
${spring.cloud.client.ipAddress}
升级后:
${spring.cloud.client.ip-address}
1.4、Spring Security
一般注册中心、配置中心都会使用安全加密,就会依赖 spring-boot-starter-security
组件,升级后有几个问题。
1.4.1、用户名和密码无法登录
因为 Spring Security 的参数进行了变更。
升级前:
security:user:name:password:
升级后:
spring:security:user:name: password:
客户端访问时候需要增加basic认证
示例如:https://github.com/bjlhx15/spring-cloud-base
启动服务注册中心:discovery-eureka-ha-security1、discovery-eureka-ha-security2
启动服务提供者:provider-business-service1、provider-business-service1
使用原始方式调用【restTemplate】comsumer-business-service1-org
注意配置restTemplate的注入
@Beanpublic RestTemplate restTemplate(RestTemplateBuilder builder) {return builder.basicAuthorization("admin", "111111").build();}
1.4.2、使用security注册中心没有注册实例
如图所示,没有注册实例,两个注册中心无法互相注册。
因为 Spring Security 默认开启了所有 CSRF 攻击防御,需要禁用 /eureka 的防御。
在 Application 入口类增加忽略eureka配置:
package com.lhx.springcloud.discovery.configuration;import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().ignoringAntMatchers("/eureka/**");super.configure(http);} }
禁用全部
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;@EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {@Overrideprotected void configure(HttpSecurity http) throws Exception {http.csrf().disable();} }
1.4.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 之后,之前的服务需要加密连接配置中心的又正常运行了。
1.5、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
Gateway 代替了 Zuul
001-Spring Cloud Edgware.SR3 升级最新 Finchley.SR1,spring boot 1.5.9.RELEASE 升级2.0.4.RELEASE注意问题点...相关推荐
- Spring Cloud 升级最新 Finchley 版本,踩了所有的坑
转载自 Spring Cloud 升级最新 Finchley 版本,踩了所有的坑 Spring Boot 2.x 已经发布了很久,现在 Spring Cloud 也发布了 基于 Spring Bo ...
- Spring cloud系列十八 Spring Cloud 从Dalston.SR5到Greenwich.SR1 的升级记录
背景 项目之前一直使用Spring Cloud Dalston.SR5,但是此版本2018年12月软件生命周期要结束,为了后续安全和维护的需要,需要将对版本进行升级.先从官网上分析D版本的后续版本的变 ...
- Spring Cloud Edgware新特性之一:解决Eureka中Jersey 1.x版本过旧的问题-不使用Jersey
为什么80%的码农都做不了架构师?>>> Spring Cloud是当前炙手可热的微服务开发框架.它的功能强大,组件丰富,设计优雅.目前Spring Cloud还在不断发展之中 ...
- Spring Cloud Edgware新特性之八:Zuul回退的改进
为什么80%的码农都做不了架构师?>>> Spring Cloud Edgware对Hystrix回退的逻辑进行了一些改进.本文将信息探讨新旧版本的回退操作,并分析的原因及改进 ...
- Spring Cloud Alibaba发布第二个版本,Spring 发来贺电
2019独角兽企业重金招聘Python工程师标准>>> 还是熟悉的面孔,还是熟悉的味道,不同的是,这次的配方升级了. 今年10月底,Spring Cloud联合创始人Spencer ...
- Spring Cloud Alibaba发布第二个版本,Spring 发来贺电 1
还是熟悉的面孔,还是熟悉的味道,不同的是,这次的配方升级了. 今年10月底,Spring Cloud联合创始人Spencer Gibb在Spring官网的博客页面宣布:阿里巴巴开源 Spring Cl ...
- 破甲两千六 Spring Cloud 教程(三):添加Spring Cloud 的 Netflix Eureka 插件,实现服务端、客户端的发现与注册
写在前面: Spring Cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选.分布式会话等等. 5大常用组件: 服务发现 ...
- spring cloud学习之消息总线(Finchley版本),以及postman下载与使用
首先来学习链接: 方志朋:https://blog.csdn.net/forezp/article/details/81041028 程序猿DD:http://blog.didispace.com/s ...
- Spring Cloud 2020年路线图发布,涵盖Spring Boot 2.3、2.4,Spring Cloud Ilford等重磅内容!
Spring Cloud 开发团队昨日公布了 Spring Cloud 2020 年的路线图,并对 Spring Cloud Greenwich 和 Hoxton 的生命周期进行了一些讲解. Spri ...
最新文章
- 深度学习(6)构造简单的神经网络
- PHPCMS V9 添加二级导航
- php截取中文字符串时乱码问题
- 在Golang开发中使用Redis
- 前端学习(1124):思考题
- android之WIFI小车编程详述
- Python案例:四种方式编程求解一元二次方程
- P3185 [HNOI2007]分裂游戏
- UISearchBar 点击取消回到原来位置时会跳动的解决方法
- 计算机等级考试网络数据,全国计算机等级考试三级信息、网络、数据库上机编程题15道...
- 怎么查询共享使用人_为什么使用“共享充电宝”的人越来越少?
- 微型计算机原理与接口技术第五版pdf,微型计算机原理与接口技术(第5版)
- 吃土豆_nyoj_234(动态规划).java
- 快手短视频产品分析报告-小白文
- depth, bedgraph, bigwig之间的联系与区别
- **中兴综合面试** **IC开发岗位**
- 将PCAP转换为Json文件的神器:joy(安装篇)
- 读不到盘如何恢复数据?硬盘不被识别数据恢复?硬盘无法识别的原因
- mysql字符串包含insert_字符串中包含关键字,insert into不成功
- Java 实验报告 了解如何使用类及其成员的修饰符,理解类的继承性,掌握方法的继承、重载和覆盖