java spring上下文:property-placeholder - set properties paths from placeholder

标签 java spring properties

<context:property-placeholder
    location="a.properties,b.properties"
    ignore-unresolvable="true"/>

结果:两个属性文件均已加载

<context:property-placeholder
    location="${properties_location}"
    ignore-unresolvable="true"/>

其中properties_location是“a.properties,b.properties”

result: Exception in thread "main" org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [a.properties,b.properties] cannot be opened because it does not exist

编辑:${properties_location} 设置如下:

System.getProperties().setProperty("properties_location", "a.properties,b.properties");
ApplicationContext ctx = new GenericXmlApplicationContext("context.xml");
...

如何以第二种方式初始化我的应用程序?在占位符中定义所有属性文件的路径。

最佳答案

您必须将其更改为:

<context:property-placeholder
location="classpath:a.properties,
          classpath:b.properties"
ignore-unresolvable="true"/>

关于java spring上下文:property-placeholder - set properties paths from placeholder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24038506/

相关文章:

java - Spring 如何使用 Java 8 类,却又在 Java 7 上运行?

java - 创建动态 JLabel 和 JButton

java - 您如何在蓝/绿部署中管理共享数据库?

java - Spring boot能否根据property文件的内容动态创建端点?

spring boot 覆盖默认的 REST 异常处理程序

c# - Sharepoint webpart 属性在一天后消失 (C#)

java - 扩展 SimpleStringProperty 的问题

java - 如何使用 twitter4j 库执行 "near"搜索推文?

html - 属性文件中的样式文本

java - 将地址映射到唯一编号