java - 如何在 PropertySource 中使用相对于用户家的路径

标签 java spring annotations applicationcontext

<分区>

Spring 表达式在 PropertySource 注释中不起作用。

@PropertySource({ "classpath:application.properties",
        "#{systemProperties['user.home']}/.app.properties" })
@Configuration
public class Config {
@Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer result = new PropertySourcesPlaceholderConfigurer();
        result.setOrder(0);
        return result;
    }
}

最佳答案

可以直接使用file:${user.home}加载用户home下的文件:

@PropertySource({ "classpath:application.properties", 
                  "file:${user.home}/.app.properties" })
@Configuration
public class Config {
}

关于java - 如何在 PropertySource 中使用相对于用户家的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29215936/

相关文章:

java - 重新写入java txt文件

java - JXLS - 如何在工作簿中创建指向 Excel 工作表的超链接

Spring认证执行两次,先成功后失败

hibernate - 在 Spring 应用程序中禁用 Hibernate 日志消息

java - 带注解的 Hibernate 字符串主键

java - 解决类ActionLogging,无法找到用于注释的类

java - 如何在 OSGI Declarative Services Annotations 中使用 java 属性文件

java - 如何使用构造函数实例化android服务?

java - XMPP 和具有静态 IP 的自定义 Openfire

java - BeanPostProcessor 示例