在使用thymeleaf時,swagger2可以正常使用,將thymeleaf改為vue之后,swagger2頁面報錯
- 原因:跨域配置類集成了WebMvcConfigurationSupport,則在配置文件中配置的相關內容會失效,需要重新指定靜態資源
- 解決辦法:在繼承了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);
}