How do I change the values of application.yaml at runtime e.g I have a server address property that I would like to change at runtime
server: address: 192.168.1.100
How do I change the values of application.yaml at runtime e.g I have a server address property that I would like to change at runtime
server: address: 192.168.1.100
I assume this is a spring application, if so you can use the jvm arguments (-D) to override the values from application.yaml file. e.g application.yaml
server:
address: 192.168.0.1
cmd line
java -jar -Dserver.address=10.10.0.1
If you need to override many properties you can also use a separate file
@SpringBootApplication
@PropertySources({
@PropertySource(name = "default", value = "classpath:default.yaml"),
@PropertySource(name = "external", value = "file:${custom.properties:}", ignoreResourceNotFound = true)
})
public class BootApplication { ... }
And launch like
java -jar -Dcustom.properties=/path/to/custom.yaml
Where custom.yaml
contains
server:
address: 10.10.10.100
port: 8888
etc: blabla
...