本文主要是介绍[noHandlerFound,1278] - No mapping for GET /swagger-ui.html---springboot集成swagger-ui报错说明,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我们在自己项目中集成swagger-ui的时候,访问其页面出现以下报错
**
解决办法的说明:
**
不敢说百分百,至少80%-90%的问题
第一种原因:
是你的配置文件集成了拦截器
第二种原因是:
application的配置文件重新定义了静态资源访问
所以总结办法是需要我们手动的把swagger-ui添加到拦截器里面去
如果已经添加了拦截器只需要添加以下代码即可
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
如果没有集成拦截器可以把此文件直接扔到自己的springboot项目里面即可
完整代码是
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport /*WebMvcConfigurerAdapter*/ {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");super.addResourceHandlers(registry);}}
这篇关于[noHandlerFound,1278] - No mapping for GET /swagger-ui.html---springboot集成swagger-ui报错说明的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!