I have a Spring Boot Web application exposing rest services.
I'm asking myself how to correctly manage profiles on Filters. Actually, my app has 2 profiles: dev and prod (you guess what it stands for...)
In prod mode, i have more filters to activate than in dev mode.
My Filters configuration class is the following:
@Configuration
public class FiltersConfig {
@Bean
public FilterRegistrationBean filterRegistrationBean(CompositeFilter compositeFilter){
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.setFilter(compositeFilter);
return filterRegistrationBean;
}
@Bean
@Profile("dev")
public CompositeFilter devCompositeFilter(){
CompositeFilter compositeFilter = new CompositeFilter();
List<Filter> filtersList = new ArrayList<>();
//filtersList.add(filter1());
compositeFilter.setFilters(filtersList);
return compositeFilter;
}
@Bean
@Profile("prod")
public CompositeFilter prodCompositeFilter(){
CompositeFilter compositeFilter = new CompositeFilter();
List<Filter> filtersList = new ArrayList<>();
//filtersList.add(filter1());
compositeFilter.setFilters(filtersList);
return compositeFilter;
}
}
My questions are:
- Is it a good practice to add @Profile on method?
- Is there a way to force the compiler to exclude classes, methods, etc. annotated with a diferent profiles than the one set as current? (I don't want my production jar/war populated with unnecessary code!)
- Does spring boot provide a clearer way to organize profiles?
thx.