springboot 使用Swagger2 报错:No mapping for GET /swagger-ui.html
这是springboot启动类在@EnableWebMvc的注释之下,原先swagger2的默认地址失效了,所有需要重新配置。在SwaggerConfig配置类中实现 WebMvcConfigurer,重写addResourceHandlers方法。访问:http://localhost:9090/swagger-ui.html。报404,控制台信息给出。
·
项目场景:No mapping for GET /swagger-ui.html
提示:这里简述项目相关背景:
No mapping for GET /swagger-ui.html
问题描述
提示:这里描述项目中遇到的问题:
访问:http://localhost:9090/swagger-ui.html
报404,控制台信息给出
原因分析:
提示:这里填写问题的分析:
这是springboot启动类在@EnableWebMvc的注释之下,原先swagger2的默认地址失效了,所有需要重新配置
@SpringBootApplication
@EnableWebMvc
@EnableTransactionManagement
@EnableSwagger2
public class SpringbootVueProjectApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootVueProjectApplication.class, args);
}
}
解决方案:
在SwaggerConfig配置类中实现 WebMvcConfigurer,重写addResourceHandlers方法
@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/");
WebMvcConfigurer.super.addResourceHandlers(registry);
}
然后就可以了
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)