How did you properly configure the different Spring profiles in the bootstrap file (for Spring Boot for Cloud Config destination servers)?

We have different configuration servers for each environment. Each spring boot application must configure a target configuration server. I tried to achieve this by setting profiles in the bootstrap.properties file, for example:

spring.application.name=app-name spring.cloud.config.uri=http://default-config-server.com --- spring.profiles=dev spring.cloud.config.uri=http://dev-config-server.com --- spring.profiles=stage spring.cloud.config.uri=http://stage-config-server.com --- spring.profiles=prod spring.cloud.config.uri=http://prod-config-server.com 

And then I set cla -Dspring.profiles.active=dev , but the loaded configuration server is always the last one installed in the file (i.e. the prod settings server will be loaded into the above settings, and then if prod is deleted, the stage will be loaded )

Is it possible to set bootstrap settings for a cloud server? I followed this example , but didn't seem to be able to get it to work. For what it's worth, these profiles work just fine to load the correct configuration (for example, app-name-dev.properties will load if the dev profile is active), but not retrieved from the corresponding configuration server.

+7
java spring-boot spring-profiles spring-cloud-config
source share
2 answers

Specifying different profiles in a single file only supports YAML files and does not apply to property files. For property files, specify the bootstrap-[profile].properties environment to override the default properties of bootstrap.properties .

So, in your case, you will get 4 files bootstrap.properties , bootstrap-prod.properties , bootstrap-stage.properties and bootstrap-dev.properties .

However, instead of this, you can also specify only bootstrap.properties by default, and when starting the application, override the property by passing -Dspring.cloud.config.uri=<desired-uri> your application.

 java -jar <your-app>.jar -Dspring.cloud.config.uri=<desired-url> 

This will take precedence over the default values.

+6
source share
 I solved a similar problem with an environment variable in Docker. 

bootstrap.yml

 spring: application: name: dummy_service cloud: config: uri: ${CONFIG_SERVER_URL:http://localhost:8888/} enabled: true profiles: active: ${SPR_PROFILE:dev} 

Dockerfile

 ENV CONFIG_SERVER_URL="" ENV SPR_PROFILE="" 

Docker-compose.yml

 version: '3' services: dummy: image: xxx/xxx:latest restart: always environment: - SPR_PROFILE=docker - CONFIG_SERVER_URL=http://configserver:8888/ ports: - 8080:8080 depends_on: - postgres - configserver - discovery 
0
source share

All Articles