spring boot应用程序属性分段和生产

时间:2018-01-20 22:03:36

标签: java spring maven spring-boot

我正在构建一个Spring Boot应用程序,我希望有多个应用程序属性具有相同的变量但不同的值(开发,登台和生产)我已经拥有我的3个文件只是我不知道如何使用@ PropertyResource并调用由maven设置的“envTarget”变量

ApplicationProperties文件

@PropertySource({ "classpath:persistence-${envTarget:dev}.properties" })

Maven pom

    <configuration>
<systemPropertyVariables>
                            <envTarget>dev</envTarget>
    <!--                        <envTarget>staging</envTarget> -->
    <!--                        <envTarget>production</envTarget> -->
                        </systemPropertyVariables>
                    </configuration>

感谢您的帮助

1 个答案:

答案 0 :(得分:3)

您可以为不同的环境提供不同的属性文件。

语法:application- {profile} .properties

e.g。 application-dev.properties,application-qa.properties

然后尝试在运行spring boot应用程序spring.profiles.active = dev。

时将配置文件作为参数传递。

有关基于个人资料的属性,请参阅Spring Boot support