Announcement Announcement Module
Collapse
No announcement yet.
Using IOC for non-spring managed beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using IOC for non-spring managed beans

    This is probably a question that has been asked several times before but I can’t seem to find it anywhere so I apologize if this is a dumb questions. I have class that is instantiated by a third-party library so I do not have control of when or how it is initialized.

    I would like this class to have a reference to a couple of my spring managed beans. However, I cannot my class cannot be a spring managed bean itself. Obviously, I can just use the web application context.

    WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext).getBean(“myManager”);

    However, this is not very “spring-like” and I was hoping there was some best practice type way to accomplish this. Any help is appreciated.

    Thanks.

  • #2
    I have not done this before, but I think the FactoryBean[1] is what you need here. Google for examples.

    Glen

    [1] http://static.springframework.org/sp...on-factorybean

    Comment


    • #3
      Thanks for the reply. Your suggestion is actually the reverse of what I need. The FactoryBean interface allows me to dependency inject objects created from other contexts.

      In my case, I need to dependency inject beans created in the spring context into an object created from another context.

      Comment


      • #4
        I believe this to be what you're looking for:

        http://static.springframework.org/sp...atconfigurable

        Note you'll have to use AspectJ load-time weaving for this.

        Comment


        • #5
          There are two threads that I am aware of that deal with registering external beans into an existing Spring context:

          http://forum.springframework.org/sho...getBeanFactory

          and

          http://forum.springframework.org/sho...light=register

          I guess for this to be applicable to your scenario, the beans you want to wire must be "autowireable" by Spring, ie., have the required setters.

          Comment

          Working...
          X