has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
时间:2020-11-19 16:46:25
收藏:0
阅读:1475
前端显示:
has been blocked by CORS policy: Response to preflight request doesn‘t pass access control check: No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
跨域问题,解决办法:
在对应的Controller上加上@CrossOrigin注解,或者在springBoot里面写一个配置类实现全局跨域:
@SpringBootConfiguration public class MyWebConfigurer implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry corsRegistry){ /** * 所有请求都允许跨域,使用这种配置就不需要 * 在interceptor中配置header了 */ corsRegistry.addMapping("/**") .allowCredentials(true) .allowedOrigins("http://localhost:8080") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowedHeaders("*") .maxAge(3600); } }
原文:https://www.cnblogs.com/Courage129/p/14005223.html
评论(0)