[英]Combinating context:property-override and PropertyPlaceholderConfigurer
I have a problem with the followingspring context configuration file: 我的以下Spring上下文配置文件有问题:
...
<context:property-override location="classpath:query_1.properties" />
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:query_2.properties" />
</bean>
....
The problem is that the properties in the file "query_2.properties" cannot be found. 问题是找不到文件“ query_2.properties”中的属性。 The exception I get ist he following one: 我得到以下例外:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException. Could not resolve placeholder...
Now my question: is it possible that the combination of context:property-override and PropertyPlaceholderConfigurer does make no sense? 现在我的问题是:context:property-override和PropertyPlaceholderConfigurer的组合可能没有任何意义吗? Can anyone explain me in simple words what is the difference between both? 谁能用简单的词解释我两者之间的区别? Any help would be appreciated. 任何帮助,将不胜感激。
Thx. 谢谢。 Horace 贺拉斯
Property placeholders, normally defined using a <context:property-placeholder location=../>
resolves the placeholders in bean definitions: 通常使用<context:property-placeholder location=../>
定义的<context:property-placeholder location=../>
解析bean定义中的占位符:
for eg. 例如
<bean name="myclass" class="MyClass">
<property name="prop1" value="${prop1val}/>
</bean>
if the location specified with property placeholder has a property with name prop1val: 如果使用属性占位符指定的位置具有名称为prop1val的属性:
prop1val=aval
then it will be replaced in the bean myclass
. 然后它将在bean myclass
替换。
PrpertyOverrideConfigurer defined using <context:property-override location="classpath:query_1.properties" />
on the other is like a push mechanism, the property is of the form beanname.property
and it would push this property into the bean with name beanname
. 另一方面,使用<context:property-override location="classpath:query_1.properties" />
类似于推送机制,该属性的形式为beanname.property
,它将将该属性推送到名称为beanname
的bean中。
For eg. 例如。 for the above case if the location had a property of: 对于上述情况,如果该位置具有以下属性:
myclass.prop1=aval
then it would inject in prop1
of myclass
bean 那么它将注入myclass
bean的prop1
中
The exception you are getting simply indicates that it is not able to find query_2.properties
file, I doubt if it is any other configuration issue. 您得到的异常只是表明它无法找到query_2.properties
文件,我怀疑这是否是其他任何配置问题。
On which one will take effect if both are defined, I think the last one will the one to take effect. 如果两者都定义,那么哪一个将生效,我认为最后一个将生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.