【发布时间】:2013-02-14 14:38:51
【问题描述】:
在 xml 配置中,我可以执行以下操作:
<context:property-placeholder
location="file:${user.home}/.config}/api.properties"
ignore-resource-not-found="true"
system-properties-mode="OVERRIDE"/>
在 java 配置中,我会执行以下操作:
/**
* @return a {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer} so that placeholders are correctly populated
* @throws Exception exception if the file is not found or cannot be opened or read
*/
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws Exception {
PropertySourcesPlaceholderConfigurer propConfig = new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new UrlResource[]
{new UrlResource("file:${user.home}/.config/api.properties")};
propConfig.setLocations(resources);
propConfig.setIgnoreResourceNotFound(true);
propConfig.setIgnoreUnresolvablePlaceholders(true);
return propConfig;
}
但是这不明白 ${user.home}
【问题讨论】:
-
今天有人对此表示赞同,所以我不明白它是重复的事实有什么意义,显然这目前有解决问题的正确答案。我也找不到重复的,版主可以提供链接吗?
-
这不是上面提到的“更改 user.home 系统属性”的副本!有关系,但不一样!请删除重复的横幅,或提供指向类似问题的正确链接。
-
这不是重复的,它特指在Spring中使用Properties,它有自己的语法和配置属性见baeldung.com/2012/02/06/properties-with-spring
-
这不是重复的
标签: java spring configuration