I've created the following properties files that are all checked into 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. 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
-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:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.