tags:

views:

49

answers:

1

I have a method invoking bean which calls a method to perform some sort of initialization on a targetBean and another bean who needs a twitter class albeit initialized.

<bean id="twitter" class="twitter4j.Twitter"></bean>

<bean id="twitterInjector"
      class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="targetObject" ref="twitter"/>
      <property name="targetMethod">
          <value>setOAuthConsumer</value>
      </property>
      <property name="arguments">
         <list>
           <value>consumerKey</value>
           <value>consumerSecret</value>
         </list>
     </property>
</bean>

<bean  id="MyPageController"
       class="com.hardwire.controller.MyPageController">
       <property name="twitter" ref="What should I put here? twitter or
                                                             twitterInjector?/>
       .
       .
       .         
</bean>

What should I inject into the MyPageController, twitterInjector or twitter?

+1  A: 

MethodInvokingFactoryBean - like all other factory beans in Spring - is primarily intended to produce a new bean; in this particular case by invoking a method of some other bean (or class). Your setOAuthConsumer method doesn't seem like it would return a bean, so using MethodInvokingFactoryBean may not be the best approach in these circumstances.

If I am mistaken and it does return a bean (in which case consider renaming it) and that's the bean you want injected in your controller then you should use twitterInjector as ref value. If you really want twitter in your controller, then you should use twitter.

ChssPly76