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

后端 未结 11 1207
半阙折子戏
半阙折子戏 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 19:02

    public class TrackingSystemApplication {

        public static void main(String[] args) {
            SpringApplication.run(TrackingSystemApplication.class, args);
        }
    
        @Bean
        public WebMvcConfigurer corsConfigurer() {
            return new WebMvcConfigurerAdapter() {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**").allowedOrigins("http://localhost:4200").allowedMethods("PUT", "DELETE",
                            "GET", "POST");
                }
            };
        }
    
    }
    

提交回复
热议问题