2012-09-07 52 views
8

我試圖找到將對象傳遞給SpringMethodInvokingFactoryBean參數列表的方法。這裏是我的Spring配置:將參數傳遞給Spring MethodInvokingFactoryBean參數列表

<bean id="qName" class="javax.xml.namespace.QName"> 
    <constructor-arg index="0" value="${com.groupgti.esb.online.tests.talentq.tns}"/> 
    <constructor-arg index="1" value="${com.groupgti.esb.online.tests.talentq.serviceName}"/> 
</bean> 

<bean id="wsdlUrl" class="java.net.URL"> 
    <constructor-arg index="0" value="${com.groupgti.esb.online.tests.talentq.url}"/> 
</bean> 

<bean id="service" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> 
    <property name="targetObject"> 
     <bean id="serviceObject" class="com.groupgti.onlinetest.talentq.jaxb.TQIntegrationV2"/> 
    </property> 
    <property name="targetMethod"> 
     <value>create</value> 
    </property> 
    <property name="arguments"> 
     <list> 
      <value type="java.net.URL">wsdlUrl</value> 
      <value type="javax.xml.namespace.QName">qName</value> 
     </list> 
    </property> 
</bean> 

這不是工作:

<value type="java.net.URL">wsdlUrl</value> 
<value type="javax.xml.namespace.QName">qName</value> 

我得到異常:

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.net.URL'; nested exception is java.lang.IllegalArgumentException: Could not retrieve URL for OSGi resource[wsdlUrl|bnd.id=573|bnd.sym=com.groupgti.esb.online.tests.talentq]: OSGi resource[wsdlUrl|bnd.id=573|bnd.sym=com.groupgti.esb.online.tests.talentq] cannot be resolved to URL because it does not exist 

這是因爲參數爲String過去了,只是wsdlUrl和而不是作爲java.net.URL對象。

我也試過這樣:

<property name="arguments"> 
    <ref bean="wsdlUrl"/> 
    <ref bean="qName"/> 
</property> 

這給了我一個異常ref屬性不屬於這裏。那麼我應該如何將一個對象傳遞給參數列表?

回答

13

找到了解決方案。我不得不添加<list>然後聲明<ref>

<property name="arguments"> 
    <list> 
     <ref bean="wsdlUrl"/> 
     <ref bean="qName"/> 
    </list> 
</property> 

這樣,一切正常。