当前位置: 代码迷 >> 综合 >> springboot 解决跨域问题 Access to XMLHttpRequest at 'XXX' from origin 'XX' has been blocked by CORS policy
  详细解决方案

springboot 解决跨域问题 Access to XMLHttpRequest at 'XXX' from origin 'XX' has been blocked by CORS policy

热度:80   发布时间:2023-12-18 10:10:58.0

application.java文件添加以下代码

@Beanpublic WebMvcConfigurer corsConfigurer() {return new WebMvcConfigurerAdapter() {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*").allowedMethods("PUT", "DELETE","GET","POST").allowedHeaders("*").exposedHeaders("access-control-allow-headers","access-control-allow-methods","access-control-allow-origin","access-control-max-age","X-Frame-Options").allowCredentials(false).maxAge(3600);}};}
  相关解决方案