添加跨域以后,swagger2页面报错,No mapping for GET /swagger-ui.html

在使用thymeleaf时,swagger2能够正常使用,将thymeleaf改成vue以后,swagger2页面报错html

  • 缘由:跨域配置类集成了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);
    }
相关文章
相关标签/搜索