简体   繁体   English

结合使用context:property-override和PropertyPlaceholderConfigurer

[英]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.

相关问题 什么是Spring的Annotation对应物 <context:property-override> ? - What is Annotation counterpart for Spring <context:property-override>? 无法使用PropertyPlaceholderConfigurer在JNDI上下文中找到属性 - Unable to find property in JNDI context using PropertyPlaceholderConfigurer PropertyPlaceholderConfigurer类中的locations属性 - locations property in PropertyPlaceholderConfigurer class 修改 PropertyPlaceholderConfigurer 的属性 - Modify property of PropertyPlaceholderConfigurer PropertyPlaceHolderConfigurer不读取Tomcat上下文XML - PropertyPlaceHolderConfigurer not reading Tomcat context XML PropertyPlaceholderConfigurer,用于读取属性文件和数据库 - PropertyPlaceholderConfigurer for reading property files and database 在PropertyPlaceholderConfigurer中使用的系统属性后缀 - System property suffix for use in PropertyPlaceholderConfigurer 春天-应用程序上下文中的bean是否动态绑定到PropertyPlaceholderConfigurer? - spring — are beans in application context binded to PropertyPlaceholderConfigurer dynamically? 春季:在应用程序上下文之外使用PropertyPlaceholderConfigurer支持 - Spring: Using PropertyPlaceholderConfigurer support outside of application context 对于导入上下文中的bean,不会解析PropertyPlaceholderConfigurer值 - PropertyPlaceholderConfigurer values are not getting resolved for beans in imported context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM