gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:52:37 30 4
gpt4 key购买 nike

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

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com