title: Using MethodInvokingFactoryBean to set up unconventional beans
body: <p>I am trying to set up <a href="http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HostConfiguration.html" rel="noreferrer">HostConfiguration</a> bean. One of the property it has is called <code>proxyHost</code>. However, the apache HostConfiguration class does not follow the java beans convention. The <a href="http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HostConfiguration.html#setProxyHost%28org.apache.commons.httpclient.ProxyHost%29" rel="noreferrer">setter</a> for the proxyHost accepts an argument of type <a href="http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/ProxyHost.html" rel="noreferrer">ProxyHost</a> whereas the <a href="http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HostConfiguration.html#getProxyHost%28%29" rel="noreferrer">getter</a> returns a String. </p>
  
  <p>I have the following snippet in my <code>applicationContext.xml</code>.</p>
  
  <pre><code>    &lt;bean id="proxyHost" class="org.apache.commons.httpclient.ProxyHost"&gt;
          &lt;constructor-arg index="0" type="java.lang.String" value="myproxy.com" /&gt;
          &lt;constructor-arg index="1" type="int" value="8087" /&gt;
      &lt;/bean&gt;
      &lt;bean id="hostConfiguration" class="org.apache.commons.httpclient.HostConfiguration"&gt;
           &lt;property name="proxyHost" ref="proxyHost" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>When I try to load the applicationContext for the app I get the following error since <code>HostConfigurationClass</code> does not have a <code>getProxyHost</code> that returns a ProxyHost or a setter that takes a String:-</p>
  
  <blockquote>
    <p>org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'proxyHost' of bean class [org.apache.commons.httpclient.HostConfiguration]: Bean property 'proxyHost' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?</p>
  </blockquote>
  
  <p>While searching on the springsource forum I came across this <a href="http://forum.springsource.org/showthread.php?t=21991" rel="noreferrer">thread</a> where it was recommended to use <a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/beans/factory/config/MethodInvokingFactoryBean.html" rel="noreferrer">MethodInvokingFactoryBean</a> to solve this.</p>
  
  <p>I am not exactly sure how using <code>MethodInvokingFactoryBean</code> would help since I would need a return type of <code>ProxyHost</code> from the method <code>getProxyHost()</code> to fix this, right? And I am not also sure about how to use it in this context. I am not clear on the internals of <code>MethodInvokingFactoryBean</code>. Therefore, if someone could please give me an example in the above context how to use <code>MethodInvokingFactoryBean</code> that would be of immense help.</p>
  
  <p>Also is this generally the accepted way to set up beans like <code>HostConfiguration</code> that do not follow convention in spring? </p>
  
  <p>Thanks!</p>