【发布时间】:2015-01-05 16:58:08
【问题描述】:
我正在使用 Spring Boot。
我在类路径之外的外部文件中声明了属性。
我将它添加到我的一个 XML 文件中:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>file:///d:/etc/services/pushExecuterService/pushExecuterServices.properties</value>
</list>
</property>
</bean>
但是,我仍然收到此错误:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'configuration.serviceId' in string value "${configuration.serviceId}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
我在这个方法的PropertiesLoaderSupport类中添加了一个断点:
public void setLocations(Resource... locations) {
this.locations = locations;
}
我注意到这个方法被多次调用,在其中一次我注意到位置参数填充:
URL [file:/d:/etc/services/pushExecuterService/pushExecuterServices.properties]
但是,我仍然收到此错误。
我仔细检查了我的项目,我没有任何额外的 PropertyPlaceholderConfigurer bean(没有检查外部依赖项)
-
我使用硬编码运行我的应用程序,我可以在 spring-boot 日志中看到 xml 中的参数:
2015-01-05 18:56:52.902 INFO 7016 --- [ main] o.s.b.f.c.PropertyPlaceholderConfigurer: Loading properties file from URL [file:/d:/etc/services/pushExecuterService/pushExecuterServices.properties]`
所以我不确定发生了什么。有什么线索吗?
谢谢。
【问题讨论】:
-
你应该做的一件事是重写你的标题,使它成为一个完整的句子,并修复问题中的拼写和格式问题(虽然我乍一看只看到几个)。
-
刚刚注意到您使用的是 Spring Boot,您应该将属性添加到
application.properties您正在与框架对抗而不是使用它。 -
是的,但我们公司的政策是在位于外部的外部文件中具有特定属性。为什么 spring-boot 会阻止我这样做?
标签: java spring spring-mvc spring-boot