Bug:No mapping for GET /onepill//swagger-ui.html


SpringBoot使用Swagger2本來可以使用的,后來出現的異常No mapping for GET /swagger-ui.html,這個異常其實不用怎么解釋,說白了就是找不到了。

遇到這種情況請先查找,最近你所添加繼承了【WebMvcConfigurationSupport】的類
如果繼承了WebMvcConfigurationSupport,則在配置文件在中配置的相關內容會失效,需要重新指定靜態資源
需要重新指定swagger靜態資源

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    /**
     * 發現如果繼承了WebMvcConfigurationSupport,則在yml中配置的相關內容會失效。 需要重新指定靜態資源
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
}

雖然不懂原因,但是很有用。


免責聲明!

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



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