[英]Spring Properties in Version Control
I've created the following properties files that are all checked into git:我创建了以下所有已签入 git 的属性文件:
**application.properties**
spring.application.name=my-service
spring.cloud.config.fail-fast=true
spring.cloud.config.uri=${CONFIG_URI:http://localhost:8888}
spring.cloud.loadbalancer.ribbon.enabled=false
**application-dev.properties**
spring.cloud.config.enabled=false
eureka.client.enabled=false
spring.application.name=my-service
spring.datasource.url=jdbc:mysql://${DB_URL:http://localhost:3306/db_example}
spring.datasource.username=dev
spring.datasource.password=local
In production all configurations are retrieved from the config server.在生产中,所有配置都从配置服务器中检索。
Questions regarding this setup:关于此设置的问题:
What options I see:我看到的选项:
Something I'm missing?我错过了什么? I want a ready-to-go dev profile, but of course adjustments are necessary for every individual developers machine.
我想要一个随时可用的开发人员配置文件,但当然每个开发人员的机器都需要进行调整。
You can define profiles for building spring which would be passed to project build time.您可以定义用于构建 spring 的配置文件,这些配置文件将传递到项目构建时间。 So define as much as profile properties file you like as :
因此,尽可能多地定义您喜欢的配置文件属性文件:
application-prod.properties
application-user1.properties
application-user2.properties
application-user3.properties
you can load your Properties by passing VM-Options in your project configuration as您可以通过在项目配置中传递 VM-Options 来加载您的属性
-Dspring.profiles.active=user2
Please note that you can define common properties which will be used by all profiles as:请注意,您可以将所有配置文件使用的通用属性定义为:
application.properties
and set your default profile in application.properties
as:并将
application.properties
的默认配置文件设置为:
spring.profiles.active=prod
Each user might have its proper Database scheme based on.每个用户都可能基于其适当的数据库方案。 :
:
spring.datasource.url=jdbc:myql://host:port/database_${user.lowername}
spring.datasource.username=database_${user.lowername}
spring.datasource.password=database_${user.lowername}
$user is an environment variable stored in the os itself $user 是存储在操作系统本身中的环境变量
I've seen this a couple different ways at my company:我在我的公司看到了几种不同的方式:
Spring Boot's Externalized Configuration documentation was really helpful for us in understanding our options and the PropertySource order. Spring Boot 的外部化配置文档对我们理解我们的选项和 PropertySource 顺序非常有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.