【发布时间】:2017-10-12 12:06:55
【问题描述】:
我有一个简单的类来使用@PropertySource 来表示属性文件,就像这样
@Component
@PropertySource(value = "file:${user.home}/.cooperp/app-conf.properties")
public class ApplicationProperties {
@Value("${mysql-location}")
private String mysqlLocation;
public String getMysqlLocation() {
return mysqlLocation;
}
public void setMysqlLocation(String mysqlLocation) {
this.mysqlLocation = mysqlLocation;
}
}
我知道如果找不到文件,可以添加ignoreResourceNotFound = true,这将使 spring 忽略它的缺失并启动应用程序。
我希望 spring 创建文件它没有找到,而不是忽略或抛出异常。
【问题讨论】:
-
您需要为此编写代码,这不是
@PropertySource的任务/功能。 -
在哪里,在 main 方法中?
-
你为什么要这样做?
-
我希望文件和属性在需要时使用默认值显示
标签: java spring-boot properties-file