0

I am using spring boot 1.5.8 and using below cors filter in application.java to enable CORS rest services to be accessible for UI developer to access from his local machine.

  @Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")
                    .allowedHeaders("*", "Access-Control-Allow-Headers", "origin" ,"Content-type","accept", "x-requested-with","x-requested-by") //What is this for?
                    .allowCredentials(true);
        }
    };
}

I want to disable this when we move to prod automatically when starting jar in prod mode using -Dspring.profiles.active=prod

Om.
  • 2,532
  • 4
  • 22
  • 22

2 Answers2

1

Add @Profile("!prod") along with bean declaration. Spring Profiles

DDovzhenko
  • 1,295
  • 1
  • 15
  • 34
0

You can mark any @Component with @Profile, so it's loaded only for specific profiles. Have a look at https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html

mp5er
  • 155
  • 13