0

I already configured the CORSConfiguration but it didn't work when I request some resources. It reported "......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." How to solve it ......

@Configuration
@EnableWebMvc
public class CORSConfiguration extends WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}
Hunter_JW
  • 3
  • 2

1 Answers1

0

the error may not cause by springboot application. because you had set the CORS config :

this is my config, and has no problem:

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH")
                .allowCredentials(true).maxAge(3600);
    }

you should check others problem, such as nginx/apache

lyq
  • 98
  • 7
  • Thanks for comment.....But it still didn't work when I use your configuration. I already check out that there's no CORS configuration in nginx and apache....What happen... – Hunter_JW Dec 03 '19 at 05:08