这两天tomcat启动是总是报如下的错误:
2015-3-3 11:57:05 org.apache.catalina.core.StandardContext listenerStart严重: Error configuring application listener of class cn.jiuling.vehicleinfosys2.listener.CustomsessionListenerjavax.naming.NameNotFoundException: Name cn.jiuling.vehicleinfosys2.listener.CustomSessionListener is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingContext.java:770) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.catalina.util.DefaultAnnotationPRocessor.lookupFieldResource(DefaultAnnotationProcessor.java:278) at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:187) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4157) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:583) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065) at org.apache.catalina.core.StandardHost.start(StandardHost.java:822) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) at org.apache.catalina.core.StandardService.start(StandardService.java:525) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodaccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)2015-3-3 11:57:05 org.apache.catalina.core.StandardContext listenerStart
研究了两天才发现是因为在自定义的监听器中使用了注解引起的。因为要用Spring注入,起码要先把类注册到Spring容器先。filter是放在web.xml里面和spring容器没有关系,先在Servlet的上下文中找到Spring的上下文,再通过Spring获取类的实例。但是Listener不归spring管,直接在web.xml中配置就能用。
新闻热点
疑难解答