java 将参数传递给 Spring MethodInvokingFactoryBean 参数列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12318062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:25:31  来源:igfitidea点击:

Pass parameters to Spring MethodInvokingFactoryBean arguments list

javaspringinversion-of-control

提问by Paulius Matulionis

I am trying to find the way to pass objects to SpringMethodInvokingFactoryBeanarguments list. Here is my Springconfiguration:

我试图找到将对象传递给SpringMethodInvokingFactoryBean参数列表的方法。这是我的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>

This is not working:

这不起作用:

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

I am getting the exception:

我收到异常:

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

This is because parameter is passed as String, just wsdlUrland not as an java.net.URLobject.

这是因为参数是作为String,wsdlUrl而不是作为java.net.URL对象传递的。

I have also tried this:

我也试过这个:

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

This gives me an exception that refattribute does not belong here. So how then should I pass an object to arguments list?

这给了我一个例外,即ref属性不属于这里。那么我应该如何将对象传递给参数列表呢?

回答by Paulius Matulionis

Found a solution. I had to add <list>and then declare <ref>:

找到了解决办法。我必须添加<list>然后声明<ref>

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

Like this, everything is working.

像这样,一切正常。