I believe this is, actually, the issue you are facing. And in that same post you have an explanation from Dave Syer and a possible solution from another user. To follow Dave's advice, this would be a possible implementation of an ApplicationContextInitializer
:
public class MyApplicationContextInitializer implements
ApplicationContextInitializer<GenericApplicationContext> {
public void initialize(GenericApplicationContext context) {
context.getEnvironment().getSystemProperties().put(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "some_profile");
}
}
and on your test class:
@ContextConfiguration(classes = JpaConfig.class, initializers = MyApplicationContextInitializer.class)
But I would say that the suggested approach (with different .properties files loaded for different profiles) in that SO post is a more elegant approach.