2012-09-07 37 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> 

这样,一切正常。