allowedOrigins cannot contain the special value "*"

简介: allowedOrigins cannot contain the special value "*"

Spring Boot的版本高于 2.4以后 ,原来的配置已经不适合目前的版本

将代码中的allowedOrigins改为allowedOriginPatterns

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 跨域支持
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

修改后

@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 跨域支持
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}


目录
相关文章
|
5月前
|
JavaScript
Invalid project name: “Philosophers-Stone“Warning: name can no longer contain capital letters
Invalid project name: “Philosophers-Stone“Warning: name can no longer contain capital letters
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
|
Android开发
The word is not correctly spelled问题
The word is not correctly spelled问题
229 0
The word is not correctly spelled问题
Don't give me five!
Don't give me five!
96 0
|
人工智能 C++
Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
775 0
|
数据库
When Tech Meets Love – Smarter Ways to NOT be Single
It’s that time of year again. Single’s Day (a.k.a Double 11) is just around the corner, people buying gifts for loved ones.
1629 0
When Tech Meets Love – Smarter Ways to NOT be Single
Error saving your changes: Description control characters are not allowed
在修改 GitHub 上的仓库描述时出现此提示信息:Error saving your changes: Description control characters are not allowed 开始以为是 Fork 来的没有修改权限,但之前没有遇到这样的情况,提示信息说的也不是这个意思。
2384 0