13

Spring MethodInvokingFactoryBeanオブジェクトを引数リストに渡す方法を見つけようとしています。これが私のSpring設定です:

<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として渡されるためです。wsdlUrljava.net.URL

私もこれを試しました:

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

refこれにより、属性がここに属していないという例外が発生します。では、どのようにしてオブジェクトを引数リストに渡す必要がありますか?

4

1 に答える 1

18

解決策を見つけました。追加<list>してから宣言する必要がありました<ref>

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

このように、すべてが機能しています。

于 2012-09-07T12:38:38.190 に答える