打开swagger-ui.html报There was an unexpected error (type=Not Found, status=404)
程序员文章站
2022-03-03 17:05:42
...
启动springboot项目后,打开swagger页面打不开报如下错误:
查了一下资料,发现是代码中WebMvcConfig自定义继承WebMvcConfigurerAdapter导致配置文件中配置的相关内容会失效,需要重新指定静态资源
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Value("${file.front-end.path}")
private String fePath;
@Value("${file.up-down-load.static-path}")
private String udlPath;
/**
* 静态资源处理
**/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations(fePath,udlPath);
}
/**
* 前后端分离,解决跨域问题
**/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 任意路径
.allowedMethods("*") //允许所有域
.allowedOrigins("*") //允许所有方法
.allowCredentials(true); //解决跨域问题
}
//允许多请求地址多加斜杠 比如 /msg/list //msg/list
@Bean
public HttpFirewall httpFirewall() {
return new DefaultHttpFirewall();
}
}
修改如下:
/**
* 静态资源处理
**/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations(fePath,udlPath);
// 增加对swagger页面的访问
registry.addResourceHandler("swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
}
重新登录,访问成功!
上一篇: MySQL学习笔记(三)多表连接查询
下一篇: MySQL 多表连接查询练习 (四)
推荐阅读
-
thymeleaf 404报错:There was anunexpected error (type=Not Found, status=404).
-
spring boot jst 模板报404 There was an unexpected error (type=Not Found, status=404).
-
There was an unexpected error (type=Not Found, status=404)---采用layui出现的问题
-
idea:springboot整合jsp出现的错误:There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp。。
-
springboot中unexpected error (type=Not Found, status=404)/WEB-INF/upload.jsp和No message available解决方案
-
Whitelabel Error Page There was an unexpected error (type=Not Found, status=404). No message availab
-
浏览器请求spring-boot模块项目报:There was an unexpected error (type=Not Found, status=404).
-
springboot集成jsp,There was an unexpected error (type=Not Found, status=404). No message available
-
springboot+thymeleaf视图映射报错:There was an unexpected error (type=Not Found, status=404)
-
小白踩坑记:springboot运行一直报错:There was an unexpected error (type=Not Found, status=404).