Spring CORS No 'Access-Control-Allow-Origin' header is present

后端 未结 11 1172
半阙折子戏
半阙折子戏 2020-11-30 18:21

I am getting the following problem after porting web.xml to java config

No \'Access-Control-Allow-Origin\' header is present on the requested resource. Origi         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 18:47

    I have found the solution in spring boot by using @CrossOrigin annotation.

    @RestController
    @CrossOrigin
    public class WebConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**");
        }
    }
    

提交回复
热议问题