Spring, so there are lots of ways to do things!
If you stay all annotations, you can use the @ActiveProfiles annotation so enable the overall set of profiles you want:
@ActiveProfiles(profiles = ProfileDefinitions.MY_ENABLED_PROFILE)
@ContextConfiguration(as usual from here...)
You see the "profiles" allows many profiles to be set. You don't need to store the profiles as constants either, but you may find that helpful:
public class ProfileDefinitions {
public static final String MY_ENABLED_PROFILE = "some-profile-enabled";
// you can even make profiles derived from others:
public static final String ACTIVE_WHEN_MY_IS_NOT = "!" + MY_ENABLED_PROFILE;
}
Using all of the above, you can selectively enable various configurations based upon the dynamic setting of the Profiles:
@Profile(ProfileDefinitions.MY_ENABLED_PROFILE)
@Configuration
@Import({these will only be imported if the profile is active!})
public class DatabaseDataStoreConfiguration {
}
@Profile(ProfileDefinitions.ACTIVE_WHEN_MY_IS_NOT)
@Configuration
@Import({if any are necessary})
public class DataStoreConfiguration {
}