I am using spring profiles to manage different set of beans. The active profile is set programmatically overriding
org.springframework.context.ApplicationContextInitializer<ConfigurableApplicationContext>.initialize()
and using
applicationContext.getEnvironment().setActiveProfiles(activeProfileEnv);
The source for the active profile is an Environment specific file. Hence it is very much possible for the profile from Environment file to be different from available profiles (on beans XML), which I would like to avoid. I do not see a "getAvailableProfiles" like accessor on ConfigurableApplicationContext which I could use for this purpose. Is it possible to validate if the active profile value is indeed available before being set?
Example sample XML
... <!-- Beans of all profiles -->
<beans profile="ProfileA">
...
</beans>
<beans profile="ProfileB">
...
</beans>
In this case my definition of available profiles is "ProfileA", "ProfileB". I do not want to set say "ProfileC" to be active profile in this case.