2 Replies Latest reply on Apr 26, 2010 4:34 AM by alexander.eckert

    Undeployment order WAR/EJB

    alexander.eckert

      Hi,

       

      when shutting down JBoss 5.1.0.GA I'll get an NPE because the destroy method of a servlet tries to call a local EJB which is already undeployd. There are no problems when using JBoss 4.2.2.GA. I build a small ear reducing it to a minimal application.

       

      I have the EJB:

       

      {code}package helloworld.server;

      import javax.ejb.SessionBean;

      /**
      * @ejb.bean
      *         name="hw/ResourceBean"
      *         type="Stateless"
      *         view-type="local"
      *      local-jndi-name="hw/ResourceBeanLocal"
      *     
      */
      public abstract class ResourceBean implements SessionBean {
         
         /**
          * @ejb.interface-method
          */
          public void startUp() {
              System.out.println(">> start up");
          }
         
          /**
           * @ejb.interface-method
           */
          public void shutDown() {
              System.out.println(">> shut down");
          }
      }{code}

       

      And the Servlet

       

       

      {code}


      import helloworld.common.ResourceBeanUtil;

       

      import javax.servlet.http.HttpServlet;

       

      /**
      * @web.servlet
      *        name="HelloServlet"
      *        load-on-startup="1"
      *
      * @web.servlet.mapping
      *         url-pattern="/hello-web/HelloServlet"
      *
      * @web.ejb-local-ref
      *        name ="ejb/hw/ResourceBeanLocal"
      *      type="Session"
      *      home="helloworld.common.ResourceBeanLocalHome"
      *      local="helloworld.common.ResourceBeanLocal"
      *      link="hello.jar#hw/ResourceBean"
      *
      */
      public class HelloServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;

       

          public void init() {
              try {
                  ResourceBeanUtil.getLocalHome().create().startUp();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
         
          public void destroy() {
              try {
                  ResourceBeanUtil.getLocalHome().create().shutDown();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      } {code}

       

      The EAR contains hello.jar (holding the EJB) and hello.war (holding the servlet). I used the default server as base and changed java2ClassLoadingCompliance to true an commented out the WarClassLoaderDeployer bean in deployers\jbossweb.deployer\META-INF\war-deployers-jboss-beans.xml.

       

      I added a jboss-dependency.xml in WEB-INF of the war file with a reference to jndi:hw/ResourceBeanLocal. But it had no effect. Deployment order is still fine but the EJB is still undeployed before the servlet.

       

      Hope you can help

        • 1. Re: Undeployment order WAR/EJB
          meme

          Hi Alexander,

           

          if you'd like to undeploy in the correct order, you should define the dependencies as you've got tried. But replace the jboss-dependency.xml with

          the jboss-web.xml (in the war) with the dependency:

           

          <jboss-web>
              <depends>[objectname of the bean]</depends>
          </jboss-web>

           

          Then it should be deployed in the correct order and it's also undeployed in the correct order.

           

          Marc

          • 2. Re: Undeployment order WAR/EJB
            alexander.eckert

            Thank you, this solved my problem.

             

            Alex