diff --git a/src/main/java/com/xujie/sys/config/CorsConfig.java b/src/main/java/com/xujie/sys/config/CorsConfig.java index 363f80f2..4d5992af 100644 --- a/src/main/java/com/xujie/sys/config/CorsConfig.java +++ b/src/main/java/com/xujie/sys/config/CorsConfig.java @@ -6,16 +6,31 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +/** + * CORS 跨域资源共享配置 + * + *

功能说明:

+ * + * + * @author System + * @since 2026-01-06 + */ @Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("*") - .allowCredentials(false) - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("*")// 允许的请求头 - .maxAge(3600); + // Spring Boot 3.x 使用 allowedOriginPatterns 替代 allowedOrigins + .allowedOriginPatterns("*") + .allowCredentials(true) // 允许携带凭证(如Cookie) + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH") + .allowedHeaders("*") // 允许所有请求头 + .exposedHeaders("*") // 暴露所有响应头 + .maxAge(3600); // 预检请求缓存时间(秒) } }