Creating Application Life Cycle Listener

Create a Class that extends ApplicationLifecycleListener.

ApplicationListener.java

package demo;

import weblogic.application.ApplicationException;
import weblogic.application.ApplicationLifecycleEvent;
import weblogic.application.ApplicationLifecycleListener;;

public class ApplicationListener extends ApplicationLifecycleListener {

public void preStart(ApplicationLifecycleEvent evt) {
System.out.println(“Event preStart received”);
}

public void postStart(ApplicationLifecycleEvent evt) {
System.out.println(“Event postStart received”);

}

public void preStop(ApplicationLifecycleEvent evt) {
System.out.println(“Event preStop received”);

}

public void postStop(ApplicationLifecycleEvent arg0) throws ApplicationException {
System.out.println(“Event postStop received”);
}
}

Add the listener element in the weblogic-application.xml description present under EAR\META-INF

weblogic-application.xml

<weblogic-application
xmlns=”http://www.bea.com/ns/weblogic/90″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<listener>
<listener-class>demo.ApplicationListener</listener-class>
</listener>
</weblogic-application>

1. Compile the ApplicationListener class and place it under EAR\APP-INF\classes

2. Create a simple Web Application and specify the web module in the application.xml present under EAR\META-INF

application.xml

<module>
<web>
<web-uri>TestApp</web-uri>
<context-root>TestApp</context-root>
</web>
</module>

5. Deploy the EAR.

Latest Comments

  1. Rafael July 19, 2011
  2. narendra May 22, 2012
    • Administrator May 28, 2012
  3. Pratap September 3, 2014
    • Administrator September 8, 2014
  4. Uma March 18, 2015

Leave a Reply