Results 1 to 3 of 3

Thread: MDB-access to objects created during web app startup?

  1. #1
    Join Date
    Jun 2005
    Posts
    2

    Default 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. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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 at 04:05 AM.

  3. #3
    Join Date
    Jun 2005
    Posts
    2

    Default

    Hello,

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

Similar Threads

  1. Replies: 1
    Last Post: Aug 24th, 2005, 02:40 PM
  2. Data Access with JaxB Objects
    By Luis Alejandro in forum Data
    Replies: 0
    Last Post: Aug 22nd, 2005, 09:27 AM
  3. Replies: 6
    Last Post: Jun 1st, 2005, 04:57 PM
  4. Contextual access to objects
    By dphollis in forum Security
    Replies: 3
    Last Post: Mar 3rd, 2005, 11:41 PM
  5. Multiple data access objects?
    By jonmor in forum Data
    Replies: 4
    Last Post: Aug 17th, 2004, 09:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •