Question

To read a Spring profile I use :

<beans profile="LOC">

I have this property set as a jvm property :

-Dspring.profiles.active=LOC

I would like to use an existing property instead which is already configured :

-Dmyproperty=LOC

Can I use spring profiles to use the existing property (myproperty) instead of spring.profiles.active ?

Was it helpful?

Solution

Have a look at source code of spring-core.jar AbstractEnvironment.java class. The system property name is hardcoded here:

   /**
     * Name of property to set to specify active profiles: {@value}. Value may be comma
     * delimited.
     * <p>Note that certain shell environments such as Bash disallow the use of the period
     * character in variable names. Assuming that Spring's {@link SystemEnvironmentPropertySource}
     * is in use, this property may be specified as an environment variable as
     * {@code SPRING_PROFILES_ACTIVE}.
     * @see ConfigurableEnvironment#setActiveProfiles
     */
    public static final String ACTIVE_PROFILES_PROPERTY_NAME = "spring.profiles.active";

So yes you can hack it and change it to your property name, or make it configurable and recompile your own version (kids please don't try this at home).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top