I am using spring boot and I have two external property files, so I can easily change its value.
But I hope that the spring application will reload the changed value when it is updated, just like reading from files. Since the properties file is simple enough to meet my needs, I hope I don't need a db or file.
I use two different ways to load the property value, the sample code will look like this:
@RestController public class Prop1Controller{ @Value("${prop1}") private String prop1; @RequestMapping(value="/prop1",method = RequestMethod.GET) public String getProp() { return prop1; } } @RestController public class Prop2Controller{ @Autowired private Environment env; @RequestMapping(value="/prop2/{sysId}",method = RequestMethod.GET) public String prop2(@PathVariable String sysId) { return env.getProperty("prop2."+sysId); } }
I will download my application using
-Dspring.config.location=conf/my.properties
source share