2017-11-17 9 views
1

からのJavaシステムプロパティと環境変数を除外しますが、ここで説明:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.htmlSpringBootのプロパティ解像度についてSpringBoot構成

私はメカニズムから除外する:それは可能

9. Java System properties (System.getProperties()). 
10. OS environment variables. 

ですか?

おかげ

+0

何か特別な理由がありますか?文脈を理解するためだけに – pvpkiran

答えて

1

あなたの春のブートアプリケーションをインスタンス化するときは、StandardEnvironmentの独自の実装を提供することができます。例えば

public static void main(String[] args) { 
    SpringApplicationBuilder applicationBuilder = new SpringApplicationBuilder(Application.class) 
      .environment(new StandardEnvironment(){ 
       @Override 
       protected void customizePropertySources(MutablePropertySources propertySources) { 
        // do not add system or env properties to the set of property sources 
       } 
      }); 
    applicationBuilder.run(args); 
} 

または代わり:

public static void main(String[] args) { 
    SpringApplicationBuilder applicationBuilder = new SpringApplicationBuilder(Application.class) 
      .environment(new StandardEnvironment(){ 
       @Override 
       public Map<String, Object> getSystemEnvironment() { 
        return new HashMap<>(); 
       } 

       @Override 
       public Map<String, Object> getSystemProperties() { 
        return new HashMap<>(); 
       } 
      }); 
    applicationBuilder.run(args); 
} 

いずれかの方法で、あなたのアプリケーションのプロパティは、任意のシステムや環境のプロパティが含まれていないことを確認してください。