記錄一次fegin調用錯誤

在使用SpringSecurity權限控制的同時使用fegin調用其他服務,產生401權限錯誤。

後臺打印錯誤: 

org.springframework.security.authentication.InternalAuthenticationServiceException: com.netflix.client.ClientException: Load balancer does not have available server for client: xxx 

前端請求返回:

{

    "timestamp": "2020-05-10T03:20:04.813+0000",

    "status": 401,

    "error": "Unauthorized",

    "message": "com.netflix.client.ClientException: Load balancer does not have available server for client: im-logic-user",

    "path": "/auth/login"

}

 

我的SpringBoot版本爲2.2.6.RELEASE,解決方法是在配置文件中加入如下配置: 

fegin:
  okhttp:
    enabled: true

上面配置的意思是採用feign.okhttp.OkHttpClient的通信方式,默認爲HttpURLConnection

問題原因是SpringSecurity攔截了fegin調用請求,也可以將fegin調用的路徑配置成資源路徑,即不需要權限驗證,還有就是幹掉SpringSecurity也是完全可以的。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章