0

i have a bean that has a constructor-arg of type A, which is created by a factory class B, B has a factory-method as 'getInstance(String name)', depends on the input name Class B return an instance of A, in the applicationContext.xml file i don't know how to inject the name into the 'getIntance' method, here is what i do so far:

<bean id="A" class="blah.blah.blah.">
  <constructor-arg type="foo.foo.foo.foo">
    <bean factory-bean="B" factory-method="getInstance" />  <== should it be getInstance('halo') instead?
  </constructor-arg>
</bean>

<bean id="B" class="boo.boo.boo.boo"></bean>
user468587
  • 4,799
  • 24
  • 67
  • 124

1 Answers1

1

You should be able to do this:

<bean id="A" class="blah.blah.blah.">
  <constructor-arg type="foo.foo.foo.foo">
    <bean factory-bean="B" factory-method="getInstance" >  
        <constructor-arg value="aName"/>
    </bean>
  </constructor-arg>
</bean>
Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • i tried your way but now i got error: No matching factory method found:factory bean 'B'; factory method 'getInstance'.. – user468587 Sep 20 '12 at 04:15
  • I tried this just now and it works cleanly for me, if you can provide your classes, I can try and debug further - here is a working gist - https://gist.github.com/3755598 – Biju Kunjummen Sep 20 '12 at 12:25