【发布时间】:2017-01-16 04:04:55
【问题描述】:
我使用的是spring boot,我有两个外部属性文件,这样我就可以很方便的改变它的值了。
但我希望 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
【问题讨论】:
标签: spring spring-boot