项目场景: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);
}
然后就可以了