Stop deployment on exception thrown in ServletContextListener
I have the following web.xml config where an exception is thrown in com.mkyong.context.ContextSecond
in the context of Initialized (). In this case, deployment does not stop and app.war continues to serve. How can I stop the deployment when an exception is thrown?
Using weblogic 12c
Generated Archetype Web Application
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.mkyong.context.ContextFirst</listener-class>
</listener>
<listener>
<listener-class>com.mkyong.context.ContextSecond</listener-class>
</listener>
ContextFirst.java
package com.mkyong.context;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class ContextFirst implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("ContextFirst:contextDestroyed");
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("ContextFirst:contextInitialized");
}
}
ContextSecond.java
package com.mkyong.context;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class ContextSecond implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("ContextSecond:contextDestroyed");
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("ContextSecond:contextInitialized");
throw new RuntimeException();
}
}
Log:
<Nov 19, 2014 1:52:36 PM EET> <Warning> <Deployer> <BEA-149124> <Failures were detected while initiating remove task for application "webservices". Error is: "[Deployer:149001]No a
pplication named "webservices" exists for operation "undeploy".">
ContextFirst:contextInitialized
ContextSecond:contextInitialized
<Nov 19, 2014 1:53:05 PM EET> <Warning> <HTTP> <BEA-101162> <User defined listener com.mkyong.context.ContextSecond failed: java.lang.RuntimeException.
java.lang.RuntimeException
at com.mkyong.context.ContextSecond.contextInitialized(ContextSecond.java:18)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:678)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
+3
source to share
No one has answered this question yet
See similar questions:
or similar: