我有一个 spring boot 应用程序,它有多个属性文件,一个用于每个环境本地、开发、测试、性能、生产。
最近我们发生了一起事件,有人忘记将新属性条目放入生产属性文件中,导致系统在生产过程中停机数小时。
我的问题是,关于如何跨多个属性文件维护属性,是否有更好的做法?
I am right now thinking of a utility, maybe a unit test that verifies each key exists in each property file and it would fail the build if it does not exist.
我做了一些搜索,但真的找不到太多。我了解 SO 问题术语,并且我在这里寻求意见。我更想知道维护属性文件的更好做法。
最佳答案
你应该为不同的环境使用不同的属性文件。比如
application-qa.properties 用于 QA 环境
application-prod.properties 用于生产环境
application-local.properties 本地环境
然后针对不同的环境使用多个脚本来启动应用,比如每个shell脚本都会包含
mvn spring-boot:run -Drun.profiles=qa
mvn spring-boot:run -Drun.profiles=prod
mvn spring-boot:run -Drun.profiles=local
例如application-local.properties 文件是:
spring.profiles.active=local
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=my_db_name
spring.data.mongodb.username=some_user_name
spring.data.mongodb.password=some_password
spring.rabbitmq.host=localhost
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.port=5672
rabbitmq.publish=true
关于java - 在 Spring Boot 应用程序中维护多个属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45607915/