一、报错信息
has been blocked by CORS policy: No 'A***ess-Control-Allow-Origin'
header is present on the requested resource.
来自一个IP端口的页面(前端项目),要访问另一个IP端口的资源(springboot请求接口),会产生跨域访问。
二、解决方法:增加配置类CorsConfig
@Configuration
public class CorsConfig implements WebMv***onfigurer {
@Override
public void addCorsMappings(CorsRegistry registry){
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedHeaders(CorsConfiguration.ALL)
.allowedMethods(CorsConfiguration.ALL)
.allowCredentials(true)
.maxAge(3600);
}
}