2015-07-11 91 views
0

我有我的應用程序上下文XML下面這些配置混合PropertySourcesPlaceholderConfigurer和Spring Bean與類型java.util.properties

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

加載我的上下文

org.springframework時,我得到了下面的異常.beans.factory.UnsatisfiedDependencyException: 在類路徑資源[dbaccessContext.xml]中定義的名稱爲 'org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0' 錯誤創建錯誤:Unsat isfied 依賴通過bean屬性表達 '屬性':無類型的 排位豆[java.util.Properties]被定義:預期 單一匹配豆但發現2: jmsProperties,systemProperties;嵌套的異常是 org.springframework.beans.factory.NoUniqueBeanDefinitionException:無類型的 排位豆[java.util.Properties]被定義:預期 單一匹配豆但發現3: jmsProperties,systemProperties

欣賞對此有任何幫助。

已更新。

我發現導致我的上下文無法加載的根本原因,因爲我的上下文有:default-autowire =「byType」,所以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"**> 

現在除去默認自動裝配= 「byType的」,我的應用程序的工作後。

回答

0

如果您更仔細地閱讀異常消息,它已經告訴您com.alu.ov.ngnms.properties.PropertySourcesPlaceholderConfigurer#0哪些不是Spring類,是否有正在被注入的properties字段。

不幸的是,代碼沒有預料到應用程序上下文中可能有多於一個的Properties bean。你必須修改這個(anoymous inner)類,並明確指定它最初期待的名稱(根據你的代碼約定,使用@Named@Resource)的Properties bean。

+0

這是我的錯字,我更新了它。只有我的代碼引用dbaccessContext.xml的上下文 – Khate

相關問題