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

后端 未结 11 1177
半阙折子戏
半阙折子戏 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:50

    Helpful tip - if you're using Spring data rest you need a different approach.

    @Component
    public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
    
     @Override
     public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        config.getCorsRegistry().addMapping("/**")
                .allowedOrigins("http://localhost:9000");
      }
    }
    

提交回复
热议问题