關於開啟Eureka安全Security認證后,客戶端死活注冊不上的問題


<div class="show-content-free">
        <p>遇到一個問題“開啟Eureka服務端的安全認證后,客戶端死活注冊不到Eureka上”,已經嘗試了以下辦法,完全搞不定。。。</p><p>客戶端出錯的版本:</p><p>spring-boot:2.0.3.RELEASE</p><p>spring-cloud:Finchley.RELEASE</p><p>查看客戶端報的錯誤:</p><p>cannot regist on known server</p><p>retrying on another server if available&nbsp; 401錯誤</p><p>spring:</p><p>&nbsp; profiles: peer1</p><p>&nbsp; security:</p><p>&nbsp; &nbsp; user:</p><p>&nbsp; &nbsp; &nbsp; name: test</p><p>&nbsp; &nbsp; &nbsp; password: 123456&nbsp; &nbsp; &nbsp; roles: USER</p><p>1.查詢資料,發現,高版本不再在Eureka服務端使用在配置文件(yml文件)中配置basic認證,如下邊這樣:</p><p>spring:</p><p>&nbsp; profiles: peer1</p><p>&nbsp; security:</p><p>&nbsp; &nbsp; user:</p><p>&nbsp; &nbsp; &nbsp; name: test</p><p>&nbsp; &nbsp; &nbsp; password: 123456&nbsp; &nbsp; &nbsp; roles: USER</p><p>而是集成WebSecurityConfigurerAdapter類,然后重寫configure方法來實現badic認證,這步做了,客戶端還是注冊不了。</p><p>2.又發現,說Eureka服務端需要關閉自我注冊,也就是在yml文件中設置registerWithEureka:false,並且fetchRegistry:false。嘗試了,發現還是不行。</p><p>3.又看到說Eureka高版本默認開啟了csrf保護,需要關閉這個才行,嘗試關閉:</p><p>http.csrf().disable();還是不行,看到另外一種寫法:</p><p>http.csrf().ignoringAntMatchers("/eureka/**");也還是不行。</p><p>4.最后又邊查資料,邊觀察,發現自己的客戶端yml寫的不對,eureka節點寫在了spring節點下,這是不對的,應該把eureka節點寫在直接靠邊的位置,這樣做就正常注冊了。(之前就知道yml對格式要求很嚴謹,今天這坑踩的可是長記性了。)</p>
      </div>
          原文地址:https://blog.csdn.net/weixin_34037977/article/details/90915691                        </div>


免責聲明!

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



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