1

要阅读我使用的 Spring 配置文件:

<beans profile="LOC">

我将此属性设置为 jvm 属性:

-Dspring.profiles.active=LOC

我想使用已配置的现有属性:

-Dmyproperty=LOC

我可以使用弹簧配置文件来使用现有属性 ( myproperty) 代替spring.profiles.active吗?

4

1 回答 1

1

查看spring-core.jar AbstractEnvironment.java类的源代码。系统属性名称在这里是硬编码的:

   /**
     * 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";

所以是的,您可以破解它并将其更改为您的属性名称,或者使其可配置并重新编译您自己的版本(孩子们请不要在家里尝试这个)。

于 2013-07-05T11:54:45.877 回答