<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/