- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章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 依赖更新 。
升级前:
1
2
3
4
|
<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>
|
eureka client 。
因为配置中心需要作为服务注册到注册中心,所以需要升级 eureka client,其他依赖没有变动.
eureka client 依赖更新 。
升级前:
1
2
3
4
|
<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>
|
spring cloud 。
注册中心里面的客户端实例ip显示不正确 。
因为 spring cloud 获取服务客户端 ip 地址配置变更了.
升级前:
1
|
${spring.cloud.client.ipaddress}
|
升级后:
1
|
${spring.cloud.client.ip-address}
|
spring security 。
一般注册中心、配置中心都会使用安全加密,就会依赖 spring-boot-starter-security 组件,升级后有几下两个问题.
1、用户名和密码无法登录 。
因为 spring security 的参数进行了变更.
升级前:
1
2
3
4
|
security:
user:
name:
password:
|
升级后:
1
2
3
4
5
|
spring:
security:
user:
name:
password:
|
2、注册中心没有注册实例 。
如图所示,没有注册实例,两个注册中心无法互相注册.
因为 spring security 默认开启了所有 csrf 攻击防御,需要禁用 /eureka 的防御.
在 application 入口类增加忽略配置:
1
2
3
4
5
6
7
8
9
|
@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) 。
1
2
3
4
5
6
7
8
9
10
|
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();
}
}
|
其实就是把 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 不能自由切换.
升级前:
1
|
spring-boot:run -drun.profiles=profile1
|
升级后:
1
|
spring-boot:run -dspring-boot.run.profiles=profile1
|
具体的请参考:https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html 。
failed to bind properties under ‘eureka.instance.instance-id' to java.lang.string
1
2
3
4
5
6
7
8
|
description:
failed to bind properties under
'eureka.instance.instance-id'
to java.lang.string:
property: eureka.instance.instance-id
value: ${spring.cloud.client.ipaddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}
origin:
"eureka.instance.instance-id"
from property source
"bootstrapproperties"
reason: could not resolve placeholder
'spring.cloud.client.ipaddress'
in value
"${spring.cloud.client.ipaddress}:${spring.application.name}:${spring.application.instance_id:${server.port}}"
|
spring.cloud.client.ipaddress这个参数已经不能被识别了 。
我们来看看源码:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# org.springframework.cloud.client.hostinfoenvironmentpostprocessor
@override
public
void
postprocessenvironment(configurableenvironment environment,
springapplication application) {
inetutils.hostinfo hostinfo = getfirstnonloopbackhostinfo(environment);
linkedhashmap<string, object> map =
new
linkedhashmap<>();
map.put(
"spring.cloud.client.hostname"
, hostinfo.gethostname());
map.put(
"spring.cloud.client.ip-address"
, hostinfo.getipaddress());
mappropertysource propertysource =
new
mappropertysource(
"springcloudclienthostinfo"
, map);
environment.getpropertysources().addlast(propertysource);
}
|
发现原来的ipaddress已经改为ip-address,那么我们在配置中心做相应的改正即可.
注:改为ip-address不会对之前的老版本的项目产生影响,会自动解析并正确赋值 。
总结 。
以上都是踩完所有的坑总结出来的解决方案,实际解决问题的过程远要复杂的多。版本变化有点大,本次已成功升级了 spring cloud 基础依赖,及注册中心(eureka server)、配置中心(config server).
其他像 gateway 代替了 zuul, 及其他组件再慢慢升级,spring cloud 的快速发展令升级变得非常蛋疼,本文记录了升级过程中踩过的所有的坑。。.
坑死了,已经保证编译、运行正常,其他还有什么坑不知道,刚升级完 finchley 这个正式版本,spring cloud 刚刚又发布了 finchley.sr1,感觉 spring cloud 变成了学不动系列了。。.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:http://www.cnblogs.com/javastack/p/9446837.html 。
最后此篇关于Spring Cloud升级最新Finchley版本的所有坑的文章就讲到这里了,如果你想了解更多关于Spring Cloud升级最新Finchley版本的所有坑的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
在接入spring-cloud-gateway时,可能有需求进行缓存json-body数据或者form-urlencoded数据的情况。 由于spring-cloud-gateway是以webfl
springcloud finchley gateway 统一异常处理 全文搜索[@@]搜索重点内容标记 1 . 问题:使用springcloud gateway时,会出现各种系统级异常,
hystrix参数使用方法 通过注解@hystrixcommand的commandproperties去配置, 如下就是hystrix命令超时时间命令执行超时时间,为1000ms和执行是不启用超
spring boot2.x已经出来好一阵了,而且spring cloud 的最新release版本finchley.release,默认集成的就是spring boot 2.x,这几天将一个旧项目
我正在使用 Spring Boot 2.0.1 版本试用新的 Spring Cloud 项目 Finchley。我已经使用 Spring Initilizr 创建了 maven 项目,并在 Eclip
我最近将我的 SpringCloud 项目从 Brixton 升级到 Finchley,一切工作正常。我正在开发 Finchley.SR2,没有遇到任何问题,但每当我将项目升级到 Finchley.R
概述: spring boot 2.0相对于之前的版本,变化还是很大的。首先对jdk的版本要求已经不能低于1.8,其次依赖的spring的版本也是最新版本5.0,并集成了功能强大的webflux等
我用 Spring boot 2 和最新版本的 Spring Cloud 尝试了 turbine + hystrix 仪表板,似乎存在一些问题并且 turbine 无法从响应式(Reactive)服务
我对微服务比较陌生,我一直在尝试使用这个 proof-of-concept application使用 Spring Boot 和 Spring Cloud。 问题是,虽然该应用程序在 Spring
我是一名优秀的程序员,十分优秀!