1. 程式人生 > >Unable to infer base url. This is common when using dynamic...錯誤解決辦法

Unable to infer base url. This is common when using dynamic...錯誤解決辦法

啟動swagger2報錯Unable to infer base url. …

具體錯誤如下
Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. 
The base url is the root of where all the swagger resources are served.
 For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/.
  Please enter the location manually:

2.7及之前的版本好像不會出現這種問題.

原因 :

Swagger2 版本 落後與 身份驗證版本 (SpringSecurity),更新到Springfox 2.8.0後,/swagger-resources/**路由不會被Authorization標頭呼叫

解決方法 :

在身份認證(SpringSecurity)的時候新增
.antMatchers("/swagger-resources/**").permitAll()