Announcement Announcement Module
Collapse
No announcement yet.
Accessing WebApplicationContext from outside Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing WebApplicationContext from outside

    Hello there! Is it possible to access (through a singleton for instance) the webappcontext? We have some classes that are not managed by spring (yet, we are performing a large refactoring on our code base to insert spring on the "archictecture") and those beans need to access some services that are now managed by spring.

    One approach I though was to create a servlet, and on its init method, grab the WebApplicationContext and add it to a Singleton class. But I would like to know if there's already something done on this.

    Regards

  • #2
    Do you really need to get hold of the entire WebApplicationContext, or do you just need to be able to inject Spring-managed beans into objects outside of the Spring container?

    If you need objects outside the container to be able to get a reference to a Spring-managed bean, then take a look at these docs: http://static.springsource.org/sprin...atconfigurable.

    Comment


    • #3
      If it is Services you are after, one option for you would be to have a jar in your classpath and a view specific jar in your war file.

      In other words, if you are using legacy and refactoring, you may not need all of that code in your war file, put it in your classpath or somewhere that the servlet container can find it. That will make it available for everything. Your services in the jar can grab all the beans you need from inside and outside of the war.

      Good luck,

      Steve O

      Comment

      Working...
      X