Can you use:
profiles = ac.getEnvironment().getActiveProfiles()
To get active profiles, then add to these and pass into:
ac.getEnvironment().setActiveProfiles(profiles, "profileName")
Pergunta
We do have some spring profiles enables via web.xml spring.profiles.active and I want to leave it that way as this is the way for our deployment team to activate profiles. in addition I want to activate some more profiles based on the presence of properties files. so I added an ApplicationContextInitializer
public class WecaApplicationContextInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext>{
@Override
public void initialize(ConfigurableApplicationContext applicationContext)
{
applicationContext.getEnvironment().addActiveProfile("someprofile");
}
but then spring ignores the spring.profiles.active context param and does not load my main profiles.
anyone has an idea how to do it?
I think I can add a ServletContextListener and add a profile to spring.profiles.active param but I think this is kind of ugly.
Solução
Can you use:
profiles = ac.getEnvironment().getActiveProfiles()
To get active profiles, then add to these and pass into:
ac.getEnvironment().setActiveProfiles(profiles, "profileName")