views:

62

answers:

2

I have an abstract class with a static method that returns either one concrete subclass

or another, depending on this static method's arguments.

How do I define a bean in spring configuration file that will invoke this static method with the arguments?

A: 

http://static.springsource.org/spring/docs/2.0.4/reference/beans.html

See sections 3.2.3.2.2 and 3.2.3.2.3 - I think that might be what you're looking for.

Andy White
+3  A: 

From the Spring documentation, you just treat the parameters as constructor arguments:

<bean id="exampleBean" class="examples.ExampleBean" factory-method="createInstance">
  <constructor-arg ref="anotherExampleBean"/>
  <constructor-arg ref="yetAnotherBean"/>
  <constructor-arg value="1"/> 
</bean>
Eric Hauser
@Eric Hauser In my case it is not a constructor, does it matter?
EugeneP
No, although confusing, it is the correct syntax for passing parameters to a factory method
Eric Hauser