This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

It is important for the method to be static because spring boot initialize those methods some times before the configuration class is fully initialized and by setting it static it can do that without fully initializing the class.

This solution works for run as Java application only because main method will not used in servlet container or JUnit-Tests.
– mg.Mar 7 '17 at 12:19

@mg. edited with another option that might help you.
– TomMar 7 '17 at 13:51

postProcessBeanFactory will be called after active profile is set already. I get log for profile No active profile set, falling back to default profiles: default and log is @ ...o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@2df6226d: startup date [...]; root of context hierarchy for my breakpoint in postProcessBeanFactory.
– mg.Mar 7 '17 at 14:06

More in detail the log output for active profile is in context of JUnit from RestControllerTests class, so active profile have to be set earlier?
– mg.Mar 8 '17 at 7:16

@mg. The best way is to use @ActiveProfiles in junit tests. Making spring boot decide the profile fully programmatically is an annoying task (from experience :). I think you should either go with the executable JAR + cli approch / loading specific properties with some kind of naming convention using ConfigurableEnvironment
– TomMar 8 '17 at 7:28