从SpringBoot配置中排除Java System属性和环境变量

时间:2017-11-17 15:07:17

标签: spring spring-boot properties

关于SpringBoot的属性解析,请在此解释:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

我想从机制中排除:

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

有可能吗?

由于

1 个答案:

答案 0 :(得分:2)

在实例化Spring Boot应用程序时,您可以提供自己的cast(column as timestamp) 实现。

例如:

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);
}

无论哪种方式,您都要确保应用程序的属性不包含任何系统或环境属性。