电光石火-穿越时空电光石火-穿越时空


swagger报错This application has no explicit mapping for /

提示一下错误

Whitelabel Error Page 
  This application has no explicit mapping for /error, so you are seeing this as a fallback.  
  Wed Aug 29 11:02:44 CST 2018  
  There was an unexpected error (type=Not Found, status=404).  
  No message available

是因为swagger-ui.html 是在springfox-swagger-ui.jar里的,因为修改了路径Spring Boot不会自动把/swagger-ui.html这个路径映射到对应的目录META-INF/resources/下面。
所以我们修改springboot配置类,为swagger建立新的静态文件路径映射就可以了

@Configuration
public class WebMVCConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
          registry.addResourceHandler("/webjars/**")
                 .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => swagger报错This application has no explicit mapping for /
本文地址:http://ilkhome.cn/index.php/archives/400/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 swagger报错This application has no explicit mapping for /,谢谢。

评论