Java爱好者 - 专注于Java技术Java爱好者 - 专注于Java技术

spring MVC 配置问题升级springboot版本后无法进入后台页面

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.

实际就是跨域限制了。
在Spring Boot升级到2.4.0之后,因为跨域配置中的.allowedOrigins不再可用
将.allowedOrigins("")替换为.allowedOriginPatterns("")即可解决问题

@Configuration
public class CorsConfig implements WebMvcConfigurer {
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
本原创文章未经允许不得转载 | 当前页面:Java爱好者 - 专注于Java技术 » spring MVC 配置问题升级springboot版本后无法进入后台页面

评论

文章评论已关闭!