views:

22

answers:

1
class SomeoneElsesAPI {
   void setDirectory(File dir){...}
   void setDirectory(String dir){...}
}

<bean id="someoneElsesAPI" class="com.someone.SomeoneElsesAPI">
   <property name="directory">
      <value type="java.lang.String">/etc</value>
   </property>
</bean>

I have a case similar to the above example, Spring is throwing an IllegalStateException indicating that it can't convert String to File.

How do I tell spring which of the overloaded methods to use? I thought spring would figure it out when I specified it in the <value type="..."> parameter.

+1  A: 

I don't know if this is a satisfactory answer, but I avoid overloading property setters that I want to be able to wire using IoC. When I do need two setters for (logically) the same property, I use different setter names ... and javadoc comments to explain what is going on.

Stephen C
Agreed, but this code is in Jetty a 3rd party app, I have posted a bug report asking them to do this, but I otherwise don't control their code. I'm thinking of using Java Config instead to get around the problem.
David Parks
Create a wrapper class that hides the overloaded setters.
Stephen C