From 3b7d2d743514cf3793c07daa5f0e1d8aca4cd528 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期日, 28 四月 2024 10:09:18 +0800
Subject: [PATCH] 文件访问bug修改
---
ycl-server/src/main/java/com/ycl/config/SecurityConfig.java | 2 +-
ycl-server/src/main/java/com/ycl/config/ResourcesConfig.java | 21 +++++++++++++++++++--
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/ycl-server/src/main/java/com/ycl/config/ResourcesConfig.java b/ycl-server/src/main/java/com/ycl/config/ResourcesConfig.java
index 2531656..81afe43 100644
--- a/ycl-server/src/main/java/com/ycl/config/ResourcesConfig.java
+++ b/ycl-server/src/main/java/com/ycl/config/ResourcesConfig.java
@@ -1,26 +1,43 @@
package com.ycl.config;
+import constant.Constants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.http.CacheControl;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import java.util.Locale;
+import java.util.concurrent.TimeUnit;
/**
* 閫氱敤閰嶇疆
- *
+ *
* @author ruoyi
*/
@Configuration
public class ResourcesConfig implements WebMvcConfigurer
{
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry)
+ {
+ /** 鏈湴鏂囦欢涓婁紶璺緞 */
+ registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
+ .addResourceLocations("file:" + PlatformConfig.getProfile() + "/");
+
+ /** swagger閰嶇疆 */
+ registry.addResourceHandler("/swagger-ui/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
+ .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic());;
+ }
/**
* 璺ㄥ煙閰嶇疆
@@ -80,4 +97,4 @@
return localeResolver;
}
-}
\ No newline at end of file
+}
diff --git a/ycl-server/src/main/java/com/ycl/config/SecurityConfig.java b/ycl-server/src/main/java/com/ycl/config/SecurityConfig.java
index de57a5f..4afe5a2 100644
--- a/ycl-server/src/main/java/com/ycl/config/SecurityConfig.java
+++ b/ycl-server/src/main/java/com/ycl/config/SecurityConfig.java
@@ -99,7 +99,7 @@
// 瀵逛簬鐧诲綍login 娉ㄥ唽register 楠岃瘉鐮乧aptchaImage 鍏佽鍖垮悕璁块棶
.requestMatchers("/login", "/register", "/captchaImage").permitAll()
// 闈欐�佽祫婧愶紝鍙尶鍚嶈闂�
- .requestMatchers(HttpMethod.GET, "/", "/*.html", "/*/*.html", "/*/*.css", "/*/*.js", "/profile/*").permitAll()
+ .requestMatchers(HttpMethod.GET, "/", "/*.html", "/*/*.html", "/*/*.css", "/*/*.js", "/profile/**").permitAll()
.requestMatchers("/swagger-ui.html", "/swagger-resources/*", "/webjars/*", "/*/api-docs", "/druid/*").permitAll()
// 闄や笂闈㈠鐨勬墍鏈夎姹傚叏閮ㄩ渶瑕侀壌鏉冭璇�
.anyRequest().authenticated()
--
Gitblit v1.8.0