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 に答える