I'm using the spring Environment Bean in my application to get the application configuration properties. I want to change the value of a property in the spring Environment from java code without restarting the application server. How can I do that?
@Service
public void MyService {
@Autowired
private Environment environment;
public void doSomething(){
String value = environment.getProperty("myproperty");
...
}
}
The Environment
implementation that you will get by default in the Spring context is actually an instance of StandardEnvironment.
StandardEnvironment
implements ConfigurableEnvironment, so if you inject a ConfigurableEnvironment
instead of the super interface you will be able to make alterations at runtime.
@Service
public void MyService {
@Autowired private ConfigurableEnvironment environment;
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