문제

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.

도움이 되었습니까?

해결책

Can you use:

profiles = ac.getEnvironment().getActiveProfiles()

To get active profiles, then add to these and pass into:

ac.getEnvironment().setActiveProfiles(profiles, "profileName")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top