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("*");
}
}
- quot allowedOrigins contain special cannotquot allowedorigins contain special body_container container element cannot attribute top-level contains cannot quot hashcode because cannot module quot container rmi quot undefined property cannot 图片资源quot项目cannot quot contain digits dashes container quot conflict response quot package cannot find