简体   繁体   中英

How to reload external property files in spring boot without tomcat restart?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM