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
Pass parameters to Spring MethodInvokingFactoryBean arguments list
提问by Paulius Matulionis
I am trying to find the way to pass objects to Spring
MethodInvokingFactoryBean
arguments list. Here is my Spring
configuration:
我试图找到将对象传递给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>
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 wsdlUrl
and not as an java.net.URL
object.
这是因为参数是作为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 ref
attribute 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.
像这样,一切正常。