我正在尝试设置HostConfiguration bean.它所拥有的财产之一被称为proxyHost.但是,apache HostConfiguration类不遵循java bean约定.该设定器用于接受的ProxyHost类型的参数的ProxyHost而吸气剂返回一个字符串.
我的帖子中有以下代码片段applicationContext.xml.
<bean id="proxyHost" class="org.apache.commons.httpclient.ProxyHost">
<constructor-arg index="0" type="java.lang.String" value="myproxy.com" />
<constructor-arg index="1" type="int" value="8087" />
</bean>
<bean id="hostConfiguration" class="org.apache.commons.httpclient.HostConfiguration">
<property name="proxyHost" ref="proxyHost" />
</bean>
Run Code Online (Sandbox Code Playgroud)
当我尝试为应用程序加载applicationContext时,我得到以下错误,因为HostConfigurationClass没有getProxyHost返回ProxyHost或带有字符串的setter: -
org.springframework.beans.NotWritablePropertyException:bean类的属性'proxyHost'无效[org.apache.commons.httpclient.HostConfiguration]:Bean属性'proxyHost'不可写或者setter方法无效:参数类型是setter匹配getter的返回类型?
在springource论坛上搜索时,我遇到了这个线程,建议使用MethodInvokingFactoryBean来解决这个问题.
我不确定如何使用MethodInvokingFactoryBean会有所帮助,因为我需要ProxyHost从方法中返回类型getProxyHost()来修复它,对吧?而且我不确定如何在这种情况下使用它.我不清楚内幕MethodInvokingFactoryBean.因此,如果有人可以请在上面的背景下给我一个例子,如何使用MethodInvokingFactoryBean这将是非常有帮助的.
这通常是设置bean的可接受的方式,就像HostConfiguration春天没有遵循惯例一样?
谢谢!
首先,实例化ProxyHost
(即ProxyHost proxyHost = new ProxyHost("myproxy1.com",8080);
<bean id="proxyHost" class="org.apache.commons.httpclient.ProxyHost">
<constructor-arg index="0" type="java.lang.String" value="myproxy1.com" />
<constructor-arg index="1" type="int" value="8088" />
</bean>
Run Code Online (Sandbox Code Playgroud)
然后实例化HostConfiguration对象
(即HostConfiguration hostConfiguration = new HostConfiguration();
<bean id="hostConfiguration" class="org.apache.commons.httpclient.HostConfiguration" />
Run Code Online (Sandbox Code Playgroud)
在此之后,使用MethodInvokingFactoryBean调用setProxyHost()上HostConfiguration并通过proxyHost作为参数.
(即hostConfiguration.setProxyHost(proxyHost);)
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<ref local="hostConfiguration"/>
</property>
<property name="targetMethod">
<value>setProxyHost</value>
</property>
<property name="arguments">
<ref local="proxyHost"/>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16725 次 |
| 最近记录: |