Spring Cloud Finchley 版本注意事項


Spring Cloud Edgware SR4 => Spring Cloud Finchley.RELEASE

版本升級及其說明

版本升級的主要對象:

jdk:1.8 +

maven 3.5.0+ ||  gradle 4.9

spring boot: 2.0.4+

spring cloud:Finchley.RELEASE

注意:我之前用的是maven3.3.9版本,項目運行總有寫奇怪的問題,后面換成maven3.6.0 ,但是倉庫地址沒換(存在以前3.3下載的jar)也一樣有問題。后面改成新的倉庫路徑,從新下載jar就好了,能正常使用了。

 

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 { @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 之后,之前的服務需要加密連接配置中心的又正常運行了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM