当前位置:网站首页>Cross domain error: when allowcredentials is true, allowedorigins cannot contain the special value "*“

Cross domain error: when allowcredentials is true, allowedorigins cannot contain the special value "*“

2022-06-10 18:41:00 nine point six

The code I wrote at the beginning is like this :

@CrossOrigin(origins = "*",allowCredentials="true",allowedHeaders = "*",methods = {
    })

Cross domain error reporting log

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource 
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: 
Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
 When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. 
 To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

 Insert picture description here

According to the prompt, I changed the code to this :

@CrossOrigin(originPatterns = "*",allowCredentials="true",allowedHeaders = "*",methods = {
    })

And then it succeeded .

If it is a configuration class

The inside addAllowedOrigin Change to allowedOriginPatterns That's it


The resistance and long , Yes, it will be

原网站

版权声明
本文为[nine point six]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101756204596.html