項目到了收尾階段,想要解決前端無法獲取靜態資源,沒法顯示用戶頭像的問題。在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/"); }
重啟項目,頁面正常訪問