0

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.

cooltoad
  • 171
  • 2
  • 12
  • 1
    it's probably [`acceptProfiles`](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/env/Environment.html#acceptsProfiles-java.lang.String...-) you are looking for –  May 05 '16 at 06:30
  • Based on "acceptsProfiles" JavaDoc , "Return whether one or more of the given profiles is active...". I guess it's more of checking if a profile is acceptable after setting active profile. Not based on available profiles. Please correct if am wrong. – cooltoad May 05 '16 at 06:36
  • Re-reading you question, you should clarify what do you mean by "available" when you talk about profile. –  May 05 '16 at 08:53

0 Answers0