Search locations for Spring Could Config Server Native
important
spring:
profiles:
active: native
cloud:
config:
server:
native:
search-locations: >
classpath:/config,
classpath:/db,
classpath:/mq
build, run and test
bash gradlew clean assemble composeUp
# do some..
bash gradlew composeDown
def default db app configs
http :8888/db/default
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 20:10:22 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native,rabbitmq:8888
{
"label": null,
"name": "db",
"profiles": [
"default"
],
"propertySources": [
{
"name": "classpath:/db/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
get db app dev profile configs
http :8888/db/dev
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Date: Sun, 24 Sep 2017 20:11:33 GMT
Transfer-Encoding: chunked
X-Application-Context: application:native,rabbitmq:8888
{
"label": null,
"name": "db",
"profiles": [
"dev"
],
"propertySources": [
{
"name": "classpath:/db/db-dev.yml",
"source": {
"db.name": "postgres",
"db.password": "postgres",
"db.server.host": "127.0.0.1",
"db.server.port": 5432,
"db.username": "postgres"
}
},
{
"name": "classpath:/db/db.yml",
"source": {
"db.name": "${$DB_NAME:postgres}",
"db.password": "${$DB_PASSWORD:postgres}",
"db.server.host": "${$DB_SERVER_HOST:0.0.0.0}",
"db.server.port": "${$DB_SERVER_PORT:5432}",
"db.username": "${$DB_USERNAME:postgres}"
}
}
],
"state": null,
"version": null
}
db-dev.properties config file
# $ http :8888/db-dev.properties
# skip http metadata ...
db.name: postgres
db.password: postgres
db.server.host: 127.0.0.1
db.server.port: 5432
db.username: postgres
mq-dev.yaml config file
# $ http :8888/mq-dev.yaml
# skip http metadata ...
mq:
password: guest
server:
host: 127.0.0.1
port: 5672
username: guest
also JSON is possible too (8888/mq-dev.json)
{
"mq": {
"password": "guest",
"server": {
"host": "127.0.0.1",
"port": 5672
},
"username": "guest"
}
}
possible variants
# http :8888/{application}/{profile}[/{label}]
# http :8888/{application}-{profile}.yml
# http :8888/{label}/{application}-{profile}.yml
# http :8888/{application}-{profile}.properties
# http :8888/{label}/{application}-{profile}.properties