-
“” (空字符串) – 意味着未定义.
-
true – 预响应将包括值设置为true的报头Access-Control-Allow-Credentials。
-
如果未定义,则允许所有凭据。
maxAge
-
预响应的高速缓存持续时间的最大时间(以秒为单位)。 值在标题Access-Control-Max-Age中设置。
-
如果未定义, 最大时间设置为1800秒(30分钟).
方法一:全局配置类
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
// 1 设置访问源地址
corsConfiguration.addAllowedOrigin(“*”);
// 2 设置访问源请求头
corsConfiguration.addAllowedHeader(“*”);
//3 设置访问源请求方法
corsConfiguration.addAllowedMethod(“*”);
//4 是否允许用户发送、处理 cookie
corsConfiguration.setAllowCredentials(true);
<