激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - Java教程 - Spring Cloud升級最新Finchley版本的所有坑

Spring Cloud升級最新Finchley版本的所有坑

2021-05-28 13:04Java技術棧 Java教程

這篇文章主要介紹了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 Cloud升級最新Finchley版本的所有坑

因為 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、配置中心無法加解密

升級后發現訪問配置中心無法讀取到配置,也無法加解密配置信息,訪問配置中心鏈接直接跳轉到了登錄頁面。

Spring Cloud升級最新Finchley版本的所有坑

現在想變回之前的 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 認證方式,如下圖所示。

Spring Cloud升級最新Finchley版本的所有坑

現在我們又可以使用以下命令加解密了。

如解密:
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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 久久思思爱 | 高清国产午夜精品久久久久久 | 国产美女做爰免费视 | 在线播放中文 | 91成人影库| 黄网站在线免费 | 国产资源在线免费观看 | 99riav国产在线观看 | 青青草免费观看 | 精品国产一区二区三区免费 | 成人午夜看片 | 国产精品手机在线亚洲 | 国产精品久久久久久久四虎电影 | 日韩999| 国产一级淫片在线观看 | 毛片免费在线 | 精品一区二区三区在线视频 | 在线日韩在线 | 男女做性免费网站 | 一级做a爰性色毛片免费 | 在线播放视频一区二区 | 免费高潮在线国 | 国产精品91久久久 | 国产成人精品免费视频大全办公室 | 久久精品亚洲一区二区 | 一色桃子av大全在线播放 | 日日摸夜夜骑 | 香蕉视频99| 一级大黄毛片 | 色猫av| 2021国产精品视频 | 久久精品国产亚洲7777小说 | 中文字幕在线观看免费视频 | 久久线视频| 精品一区二区三区日本 | 国产一区二区免费看 | 国产精品午夜未成人免费观看 | 欧美午夜网 | 亚洲aⅴ免费在线观看 | 日本网站一区二区三区 | 羞羞视频.www在线观看 |