Install profile on bootstrap.yml in spring cloud to target another configuration server

I use docker compose to run all my microservices. For each service, I give a short host name.

version: '2' services: config: image: springbox-config-server restart: always ports: - "8890:8890" discovery: image: springbox-eureka restart: always ports: - "8763:8763" 

Therefore, in my microservice, I have to target the configuration server with its short host name.

 spring: application: name: myservice cloud: config: uri: http://config:8890 fail-fast: true 

However, when I run them locally in my IDE without dockers, the short host name cannot be resolved.

So, I am looking for a solution to configure another configuration server to suit my environment.

+6
spring-cloud docker
source share
1 answer

I find a solution. We mainly use the spring profile to enrich the bootstrap file. for example

 spring: application: name: myservice cloud: config: uri: http://config:8890 fail-fast: true --- spring: profiles: development cloud: config: uri: http://localhost:8890 

The good news is that we don’t need to rewrite all the properties in the profile. Default properties are inherited. For example, when a development profile is enabled, my application name is inherited from the default, which is always called myservice.

To activate a profile, start the service with the following property

 -Dspring.profiles.active=development 
+12
source share

All Articles