如何允许Spring Boot中启用CORS的所有请求?

Mai*_*sad 4 spring spring-boot

在我的Spring boot应用程序中,目前我有这个类:

@SpringBootApplication
public class TestApplication {
   public static void main(String[] args) {
      SpringApplication.run(TestApplication.class, args);
   }
   @Bean
   public WebMvcConfigurer corsConfigurer() {
      return new WebMvcConfigurerAdapter() {
         @Override
         public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/user").allowedOrigins("http://localhost:3000");
         }
      };
   }
}
Run Code Online (Sandbox Code Playgroud)

它只允许我访问或写入http://localhost:3000,但我希望这个休息方法可以被所有东西访问,比如http://localhost:1000http://localhost:9999或任何网站。

我怎样才能启用它?

Mai*_*sad 9

在我@SpringBootApplication带注释的课程中,我添加了以下内容:

@Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").allowedOrigins("*");
            }
        };
    }
Run Code Online (Sandbox Code Playgroud)