1. 程式人生 > >Spring Could 2.0 eureka 配置spring.security後其他服務無法連線註冊中心

Spring Could 2.0 eureka 配置spring.security後其他服務無法連線註冊中心

 

 

Eureka的Server端和Client端成功啟動,服務註冊、發現都正常。但是在Client端向Server端請求註冊服務時,需要驗證使用者名稱和密碼,問題出現。

分析原因

查資料瞭解到新版(Spring Cloud 2.0 以上)的security預設啟用了csrf檢驗,要在eurekaServer端配置security的csrf檢驗為false

解決步驟

  1. 新增繼承類 WebSecurityConfigurerAdapter ;
  2. 啟用 @EnableWebSecurity 註解;
  3. 覆蓋父類的 configure(HttpSecurity http) 方法,禁用掉 csrf。
  4. 廢話不多說,上圖了