1.解决问题:When allowCredentials is true, xxxxxxx , using “allowedOriginPatterns“ instead
2.3版本跨域配置如下
/**
* 跨域问题解决
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*")
.maxAge(3600)
.allowCredentials(true);
}
}
1.1.解决方法:
Spring官网有类似问题:https://github.com/spring-projects/spring-framework/issues/26111
大致意思为:提供了allowedOriginPatterns方法供使用。原本的allowCredentials为true时,allowedOrigins不能使用 * 号匹配
/**
* 跨域问题解决
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("*")
.allowedHeaders("*")
.maxAge(3600)
.allowCredentials(true);
}
}
其实解决跨域大分类有2种方式,一种是利用注解,一种写个配置类
2.解决跨域的几种方式
2.1.CorsFilter 方式设置跨域
&

文章介绍了在Spring框架中处理跨域问题的不同方法,包括CorsConfig的配置、CorsFilter和拦截器的应用,以及如何通过Nginx和WebFilter进行跨域管理。特别强调了`allowedOrigins`和`allowedOriginPatterns`的区别以及在allowCredentials为true时的处理。

4886

被折叠的 条评论
为什么被折叠?



