SpringJava配置中的引用${user.home}

SpringJava配置中的引用${user.home},java,spring,configuration,Java,Spring,Configuration,在xml配置中,我可以执行以下操作: <context:property-placeholder location="file:${user.home}/.config}/api.properties" ignore-resource-not-found="true" system-properties-mode="OVERRIDE"/> /** * @return a {@link org.springframework.cont

在xml配置中,我可以执行以下操作:

<context:property-placeholder
        location="file:${user.home}/.config}/api.properties"
        ignore-resource-not-found="true"
        system-properties-mode="OVERRIDE"/>
/**
 * @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}

请尝试
${sys:user.home}
引用系统属性。对于系统环境,请使用
${env:THE-env-VAR-NAME}

在@Arun BC上不起作用,如果它对您不起作用,则这不是进行向下投票的原因。本例中的原因是希望使用系统变量
user.home
,因此应使用语法
${sys:user.home}
。然而,你转向显然不存在的环境变量。今天有人对此进行了投票,所以我不认为这是一个重复的事实有多重要,很显然,这目前有正确的答案来解决问题。我也找不到副本,请版主提供一个链接?这不是上面提到的“Change user.home system property”的副本!这是相关的,但不一样!请删除重复的横幅,或提供指向类似问题的正确链接。这不是重复的,它特别指的是在Spring中使用属性,它有自己的语法和配置属性。请看,这不是重复的