我正在使用spring启动,并且我有两个外部属性文件,以便我可以轻松更改其值。当外部属性文件更改时重新加载属性值,弹簧启动
但我希望spring应用程序在更新时会重新加载更改的值,就像从文件中读取一样。由于属性文件很容易满足我的需要,所以我希望我不需要数据库或文件。
我用两种不同的方式来加载属性值,代码示例会喜欢:
@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);
}
}
我启动我的应用程序与
-Dspring.config.location=conf/my.properties