Announcement Announcement Module
Collapse
No announcement yet.
Load on deployment Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load on deployment

    Is there a way to have the applicationContext.xml file loaded on deployment? I have a Spring JMX bean defined in my ejb's context and it is unreachable until the ejb is accessed. This is undesirable.

    Thanks
    T

  • #2
    You may use ContextLoaderListener or ContextLoaderServlet for this purpose. Note that you do not need to have a web application in order to use this feature. It is a perfect fit for initializations.

    Regards,
    Andreas

    Comment


    • #3
      Thanks for the quick reply! I'm glad to see this is possible. Do you have any links to how this is accomplished? Would I put the related code in the onEjbCreate() method?

      Comment


      • #4
        I've been trying to wrap my head around this one, but I do not see how it is possible. If I put it in the onEjbCreate method, the context is still not initialized until the EJB is accessed.

        Comment


        • #5
          The more I experiment with this, the less likely this is. Maybe my problem was poorly defined. I need to start an MBean service when an EJB is deployed. There is no servlet in this scenario. This is not ideal, but there seems to be absolutely no way to create a self-deploying MBean service. Therefore, I have tied it to an EJB that will provide an access point and (hopefully) load the MBean service and start it on deployment.

          As I see it, the problem is that Spring's JMX functionality pre-supposes that you will tie your JMX service to a servlet where it can be loaded on initialization. I do not see an initialization option in the world of EJBs. As an aside, this assumption is pretty limiting. I can't imagine very many people that would want to only use a service with a webapp and never without the webapp. It's bad enough that I'm trying to tie it to an EJB. This seems to defeat the purpose of a service.

          Please correct me if I'm wrong. I'd love to be wrong in this case.

          Comment


          • #6
            It is true that there is no single initialization point for EJBs. IMHO that is a flaw of the EJB spec. Initialization is however covered in the servlet spec. Therefore I proposed to use a servlet or listener (spring does provide usefule classes here out of the box).
            Actually I see no obstacle in initializing your JMX bean from a listener or servlet. Just deploy a war with a ContextLoaderListener loading your application context where the JMX bean is defined. That would be all.

            Regards,
            Andreas

            Comment


            • #7
              Thanks for the reply. I decided to build a war for my JMX MBean. It is weird to me to do this, as I am accustomed to building a sar for this purpose, but it is turning out to be a worthwhile endeavor. Every time I have difficulty, there turns out to be an easy answer that I overlooked because it is in fact so simple. I have always enjoyed Spring's proxying to keep my apps decoupled, but I see now how very useful it is in other facets of app development. Now I can use my EJB as a mere facade that acts as a transactional access point for distributing my app components, as I desired. I just needed to look at the problem differently. Thanks again.

              Comment

              Working...
              X