Delete Method Cors issue in Rest Controller

前端 未结 1 1396
心在旅途
心在旅途 2021-01-05 04:21

I have some Rest endpoints in my project which I call from a client application in another server. I have successfully disabled Cors using the @CrossOrigin anno

相关标签:
1条回答
  • 2021-01-05 04:40

    I found a solution, after analyzing http requests, I noticed that Access-Control-Allow-Methods header was missing the DELETE method, so I have added it by delete the @CrossOrigin annotation, and adding this bean to the configuration:

            @Bean
            public WebMvcConfigurer corsConfigurer() {
                return new WebMvcConfigurerAdapter() {
                    @Override
                    public void addCorsMappings(CorsRegistry registry) {
                        registry.addMapping("/robotpart/**").allowedOrigins("*").allowedMethods("GET", "POST","PUT", "DELETE");
    
    
                    }
                };
            }
    
    0 讨论(0)
提交回复
热议问题