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);
    }
}

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-14
  • 2021-09-16
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2021-07-30
  • 2021-07-22
相关资源
相似解决方案