我正在开展一个maven项目。在tomcat7中创建了一个监听器类,但是当我部署时,我得到以下错误:
听众类
public class DBInitialisationListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
System.out.println("Db Initialised");
}
public void contextDestroyed(ServletContextEvent event) {
DatabaseFactory.close();
System.out.println("Db Closed");
}
}
的web.xml
<listener>
<listener-class>com/nrift/ovmgmt/core/DBInitialisationListener</listener-class>
</listener>
我的错误日志:
Sep 04, 2014 2:14:31 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class com/nrift/ovmgmt/core/DBInitialisationListener
java.lang.NoClassDefFoundError: IllegalName: com/nrift/ovmgmt/core/DBInitialisationListener
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:655)
at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4733)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
答案 0 :(得分:1)
类名是监听器配置不正确。使用如下。
<listener>
<listener-class>com.nrift.ovmgmt.core.DBInitialisationListener</listener-class>
</listener>
答案 1 :(得分:1)
您必须将包类指定为definde,我的意思是,使用点&#34;。&#34;
<listener>
<listener-class>com.nrift.ovmgmt.core.DBInitialisationListener</listener-class>
</listener>
原因是因为Maven找不到班级
要检查是否已在<listener-class>
标记中正确添加了该类,请尝试在课程上制作CTRL+Click