Given a config client bootstrap.yml:
spring:
...
cloud:
config:
uri: ${SPRING_CONFIG_URI:http://localhost:9000}
fail-fast: true
The environment variable SPRING_CONFIG_URI
needs to be set at runtime. We can debate this code smell another time, but for this exercise this URI is only known when the service starts (it has to do with fetching randomized SRV records).
Is there a Spring way to set/override some of the bootstrap.yaml
parmeters?
Here is what I tried:
@SpringBootApplication
public class Application {
public static void main( String[] args ) throws Exception
{
String configServerPort = DnsHelper.resolveSrv("configserver.local");
// This doesn't work
System.setProperty("SPRING_CONFIG_URI", configServerPort);
// This doesn't work
// Use reflection to change the in-memory environment variables
// @see https://stackoverflow.com/a/7201825/1938889
setEnv( Map.of( "SPRING_CONFIG_URI", configServerPort ) );
// After the environment variable is set, then start the service
Application.run( Application.class, args );
}
...