Change and persist on yaml a change on an attribute annotated with @Value

Viewed 2404

Supposed that I have an attribute of an class annotated with @Value

@RestController
public class MyController{
    @Value("${my.host}")
    protected String myHost;
...

And I have this attribute mapped on my spring configuration yml file:

...
my.host: 10.0.103.144
my.port: 3003
...

Is there a way to change the value contained in the attribute myHost and automatically reflect it on my configuraton yml file for this change be persistent?

For example, invoke this with "anotherHost":

private changeHost(String newHost) {
    myHost = newHost;
}

Would result into this on configuration file:

...
my.host: anotherHost
my.port: 3003
...
1 Answers
Related