Fork me on GitHub

[Java][Servlet] Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]

Background: Servlet version 3.1(3.0之后就有了@WebServlet注解)

Error

严重: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
java.lang.NullPointerException
	at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:316)
	at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:492)
	at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:821)
	at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
	at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:877)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

十月 27, 2016 11:36:07 下午 org.apache.coyote.AbstractProtocol destroy
信息: Destroying ProtocolHandler ["ajp-nio-8009"]
十月 27, 2016 11:36:07 下午 org.apache.coyote.AbstractProtocol destroy
严重: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
java.lang.NullPointerException
	at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:316)
	at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:492)
	at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:821)
	at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:551)
	at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:877)
	at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:292)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

我首先分析了是不是端口号被占用了的问题,使用netstat -ano|findstr "8080"未找到有使用该端口的进程。于是我回头浏览代码,并将web.xml中的servlet配置删除掉,tomcat正常启动,难道是下面的servlet配置错了?

  <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>com.study.servlet.LoginServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/loginServlet</url-pattern>
  </servlet-mapping>

这个配置没有问题,接下来就去看servlet的实现了,发现这个类有个注解,查看了一下这个注解的含义

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
...
}

这里将@WebServlet("/loginServlet")注解去掉,tomcat就能启动成功,于是问题就来了,为什么注释掉这段注解就OK了?
我们先看看这段注解是干什么的:
~~
在Servlet3.0之后,可以使用注解来告知Servlet容器哪些Servlet会提供服务,使用@WebServlet("/loginServlet")注解表示了当url的请求为loginServlet,则由LoginServlet实例提供服务。所以当你添加了注解,又在web.xml中进行了servlet的配置,我猜想会造成冲突,servlet会初始化2次,那么我们删掉注解或者删掉web.xml中的配置都能正常启动tomcat。
~~

以上是我面对这个Error找出的解决方案,不一定适合你的Error,仅供参考。

posted @ 2016-10-27 23:40  种花生的读书人  阅读(21245)  评论(0编辑  收藏  举报

该博客仅作为记录笔记,转载随意