混合了PropertySourcesPlaceholderConfigurer和类型为java.util.properties的Springbean
我在我的应用程序上下文xml上有以下配置混合了PropertySourcesPlaceholderConfigurer和类型为java.util.properties的Springbean,java,spring,Java,Spring,我在我的应用程序上下文xml上有以下配置 <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jmsconfig.properties</va
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jmsconfig.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="order" value="1"/>
</bean>
<bean id="jmsConfigPropertyPlaceHolder" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<bean class="org.springframework.core.io.FileSystemResource">
<constructor-arg value="#{systemEnvironment['SHARED_DIR']}/messaging/broker.properties" />
</bean>
</list>
</property>
</bean>
<bean id="jmsProperties" class="java.util.Properties">
<constructor-arg>
<props>
<prop key="transportURI">${transportURI}</prop>
<prop key="maxConcurrentConsumers">${maxConcurrentConsumers}</prop>
<prop key="timeToLive">${timeToLive}</prop>
<prop key="cacheConsumer">${cacheConsumer}</prop>
<prop key="cacheProducer">${cacheProducer}</prop>
<prop key="deliveryPersistent">${deliveryPersistent}</prop>
</props>
</constructor-arg>
</bean>
类路径:jmsconfig.properties
${transportURI}
${maxConcurrentConsumers}
${timeToLive}
${cacheConsumer}
${cacheProducer}
${deliveryPersistent}
我在加载上下文时遇到以下异常
org.springframework.beans.factory.unsatifiedDependencyException:
创建名为的bean时出错
'org.springframework.context.support.propertysourcesplaceplaceconfigurer#0'
在类路径资源[dbaccessContext.xml]中定义:未满足
通过bean属性“properties”表示的依赖关系:No
定义了[java.util.Properties]类型的限定bean:预期
单个匹配bean,但找到2个:
JMS属性、系统属性;嵌套异常是
org.springframework.beans.factory.NoniqueBeandDefinitionException:否
定义了[java.util.Properties]类型的限定bean:预期
单个匹配bean,但找到3个:
JMS属性、系统属性
谢谢你在这方面的帮助
更新
我找到了导致我的上下文无法加载的根本原因,因为我的上下文有:default autowire=“byType”,所以Spring将尝试按类型注入我的所有Spring属性
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
**default-autowire="byType"**>
删除default autowire=“byType”后,我的应用程序现在可以工作了。如果您仔细阅读异常消息,它已经告诉您
com.alu.ov.ngnms.properties。PropertySourcesPlaceholderConfigurer#0
不是Spring类,它有一个属性
字段,正在注入
不幸的是,代码没有预料到在应用程序上下文中可能有多个
属性
bean。您必须修改该(异常内部)类,并通过名称(使用@Named
或@Resource
,具体取决于您的代码约定)显式指定它最初期望的属性
bean。这是我的输入错误,我更新了它。我的代码只引用dbaccessContext.xml的上下文