SpringMVC整合Swagger出現Unable to infer base url. This is common when using dynamic servlet 錯誤

昨天在使用SpringMVC整合swagger2時出現瞭如下問題:


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:

困擾了半下午,網上找了很多方法試了都不行。

最終測試發現,根本原因還是spring沒有加載到swagger2的配置類。

直接原因:

<context:component-scan> 沒有掃描到swagger2的配置類。或者沒有在xml中注入swagger2的配置類bean.

解決方法1. 在<context:component-scan> 的base-package中包含swagger2配置類所在包。

解決方法2. 在spring的xml配置文件中注入swagger2配置類bean.


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