Announcement Announcement Module
Collapse
No announcement yet.
MDB-access to objects created during web app startup? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MDB-access to objects created during web app startup?

    Hello,

    I'll start by explaining our current setup. We have a web application that, at initialization time, all singleton objects are created and correctly wired by Spring (pretty usual stuff). Among these singleton objects we have DAOs and services objects that are invoked when users submit HTML forms to the server.

    We also have an EJB tier in our application. The only EJBs we have are MDBs. These beans get messages from external resources and then need to invoke exactly the same services and DAOs objects that the web tier uses. I spent some time going over the documentation on how to integrate EJBs and Spring and then we did as suggested: MDBs extend AbstractJmsMessageDrivenBean and an implementation for the setMessageDrivenContext() method is provided. This worked fine but... basically, what is happening here is that I am loading (and wiring) into the JVM memory exactly the same objects that were loaded when the web application was initialized. So, now I have two copies of all the service and DAO objects in memory.

    So, my question is... is there a way to get a reference, in the MDBs, to the same services and DAO objects that were instantiated and wired by Spring during the startup of the application? In the MDBs, of course, we do not have access to the ServletContext, and hence, we do not have access to the WebApplicationContext which would return the already wired objects that the MDBs need.

    A possible solution that we thought of (to avoid having two instances of every service and DAO object) was to move all our services and DAOs to the EJB tier and then have the web tier contact session EJBs which would then call the correponding service and/or DAO object. This way, the instantiation and wiring of objects by Spring would happen the first time a session EJB is invoked instead of occurring when the web application is initialized. We don't like this solution since we would be adding session EJBs to the application which are not really needed... it just seems unnecessary extra overhead.

  • #2
    You can create two application contexts. One for Web-only objects, and one for the shared objects. http://forum.springframework.org/sho...?t=15451<br /> has an example of this.
    Last edited by robyn; May 16th, 2006, 05:05 AM.

    Comment


    • #3
      Hello,

      Thanks for the link to the thread. Using that information I was able to do exactly what we wanted.

      Comment

      Working...
      X