I use docker compose to run all my micro services. For each service I give it a short hostname.
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 micro service I have to target the configserver with its short hostname.
spring:
application:
name: myservice
cloud:
config:
uri: http://config:8890
fail-fast: true
However, when I run them locally in my IDE without docker, the short hostname can't be resolved.
So I'm looking for a solution to target different config server according to my environment.
I find the solution. Basically, we use 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 have to rewrite all properties in a profile. The default properties are inherited. For instance, when the development profile is enabled, my application name is inherited from the default one called always myservice.
To activate the profile, start the service with the following property
-Dspring.profiles.active=development
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With