Reputation: 641
I'm trying to read external property file in spring boot application. This process is currently working perfectly. As my requirement changed, I need to set some property on the go and that property should be reloaded automatically in application without manually restarting Tomcat. Currently I have two POJO for the property files and it gets initialized by spring. I want to initialize it manually while I call my rest service. I have created I tried with @Refreshscope but not working.
AppController.java
//initial code segments
public class AppController {
LocalProperties localProperties;
@PostMapping(value = "/getdata", produces = "application/json")
public String getResponse(@RequestHeader HttpHeaders headers, @RequestBody String request) {
//Somthing like below method to initilize external properties
loadExternalPropeteries();
//use the property classes in business logic
}
private void loadExternalPropeteries() {
//Assuming the the object wil be created now
localProperties=new LocalProperties();
}
}
Currently the POJO for property LocalProperties.java
@PropertySource("file:${spring.config.location}/localConfig.properties")
@ConfigurationProperties(ignoreUnknownFields = false)
public class LocalProperties {
@Value("${server.url}")
private String url;
}
Upvotes: 1
Views: 1911
Reputation: 84
try to follow instruction from https://www.baeldung.com/spring-reloading-properties#reloading-cloud
Upvotes: 1