项目到了收尾阶段,想要解决前端无法获取静态资源,没法显示用户头像的问题。在application.yml文件里检查文件上传路径和静态文件路径
hrms : # 本地:local uploadType: local path : #文件上传根目录 设置 upload: F://opt//upFiles #webapp文件路径 webapp: F://opt//webapp
spring:
resource:
static-locations: classpath:/static/,classpath:/public/
然后确定前端请求连接和后端@GetMapping("/**")里的值一样,数据库中写好测试头像测试路径,运行访问前端页面。
静态资源问题解决,测试一下其他方法康康有没有问题,毕竟我做事一向严谨
访问localhost:xxxx/xxxx/swagger-ui.html,报错
果然老天爷还是不想让我太好过
既然无法访问swagger-ui.html页面,原因大致有两个,一个路径问题,一个找不到swagger-ui.html页面。检查过后确认路径没错,那就是页面问题了。
swagger-ui.html页面默认存放在/META-INF/resources/下,没改静态路径前swagger还是好好的,那么解决方法有两个:一个是在application.yml文件的静态资源路径中加入/META-INF/resources/
spring:
resource:
static-locations: classpath:/static/,classpath:/public/,classpath:/META-INF/resources/
一个就是在跨域配置类中加入swagger-ui.html和所在路径
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); }
重启项目,页面正常访问