你的位置:首页 > Java教程

[Java教程]Server Tomcat v7.0 Server at localhost failed to start.错误可能原因之一


故事由来:

  学Servlet中,突然发现启动Tomcat时出现这个问题

故事梗概:

  学习servlet尽然能碰到服务器起不来的,百思不得其解,然后我百度,我FQgoogle,找stackoverflow。找到了不少答案,比如stackoverflow给出说是在

<workspace-directory>\.metadata\.plugins\org.eclipse.core.resources

  中有个.snap文件删掉,就可解决这个问题,我试了不行。stackoverflow的链接如下:http://stackoverflow.com/questions/13244233/server-tomcat-v7-0-server-at-localhost-failed-to-start-without-stack-trace-whi。

百度下,Myexception网给出答案是1、端口被占用,2、启动时间不够,3、eclipse引发的问题,4、重新启动电脑(最笨的办法,如果不停的出现,不停的重起会烦死的。)。下面是原文链接。这答案给的没有一个是我要的,所以,以后还是尽量谷歌,百度感觉真心不靠谱。

故事真相:

  在eclipse这个强大的软件中,我们省略很多手动写代码的时间,过程如下:

 

在上图中点击finish后就生成下面的代码。

比如在eclipse中,我们建一个新的 servlet文件后,代码中会生成如下一大块代码。

 1 import java.io.IOException; 2 import javax.servlet.ServletException; 3 import javax.servlet.annotation.WebServlet; 4 import javax.servlet.http.HttpServlet; 5 import javax.servlet.http.HttpServletRequest; 6 import javax.servlet.http.HttpServletResponse; 7  8 /** 9  * Servlet implementation class ServletDemo10 */11 @WebServlet("/ServletDemo")12 public class ServletDemo extends HttpServlet {13   private static final long serialVersionUID = 1L;14    15   /**16    * @see HttpServlet#HttpServlet()17   */18   public ServletDemo() {19     super();20     // TODO Auto-generated constructor stub21   }22 23   /**24    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)25   */26   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {27     // TODO Auto-generated method stub28     response.getWriter().append("Served at: ").append(request.getContextPath());29   }30 31   /**32    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)33   */34   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {35     // TODO Auto-generated method stub36     doGet(request, response);37   }38 39 }

而这里面,留意下有个注解

@WebServlet("/ServletDemo")

这个注解是eclipse帮我们生成好的,而问题恰恰就出在这。我们知道,每次我们新建一个servlet后会在web.

<?xsi:schemaLocation="http://java.sun.com/http://java.sun.com/class>com.vivizhang.servlet.HelloWorldServlet</servlet-class> </servlet> <servlet-mapping>  <servlet-name>ServletDemo</servlet-name>  <url-pattern>/HelloServlet</url-pattern> </servlet-mapping></web-app>

所以问题的真相就是配置自动生成的注解冲突了,导致如下的错误(截取):

 A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ServletDemo]]  at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)  at java.util.concurrent.FutureTask.get(FutureTask.java:111)  at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1120)  at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)  at java.util.concurrent.FutureTask.run(FutureTask.java:166)  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:722)Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloServlet]]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)  ... 7 moreCaused by: java.lang.IllegalArgumentException: The servlets named [ServletDemo] and [com.vivizhang.servlet.ServletDemo] are both mapped to the url-pattern [/ServletDemo] which is not permitted  at org.apache.catalina.deploy.Web293)  at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2462)  at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2137)  at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2098)  at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2090)  at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2090)  at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2090)  at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2090)  at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1304)  at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)  at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)  at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5472)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  ... 7 more九月 18, 2016 4:40:37 下午 org.apache.catalina.core.ContainerBase startInternalSEVERE: A child container failed during startjava.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]  at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)  at java.util.concurrent.FutureTask.get(FutureTask.java:111)  at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1120)  at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:738)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  at org.apache.catalina.startup.Catalina.start(Catalina.java:693)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  at java.lang.reflect.Method.invoke(Method.java:601)  at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)  at java.util.concurrent.FutureTask.run(FutureTask.java:166)  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:722)Caused by: org.apache.catalina.LifecycleException: A child container failed during start  at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)  at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  ... 7 more九月 18, 2016 4:40:37 下午 org.apache.catalina.startup.Catalina startSEVERE: The required Server component failed to start so Tomcat is unable to start.org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8006]]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)  at org.apache.catalina.startup.Catalina.start(Catalina.java:693)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  at java.lang.reflect.Method.invoke(Method.java:601)  at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)  at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)  at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:738)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  ... 7 moreCaused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)  at org.apache.catalina.core.StandardService.startInternal(StandardService.java:444)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  ... 9 moreCaused by: org.apache.catalina.LifecycleException: A child container failed during start  at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1128)  at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)  ... 11 more

这里的问题出在:

The servlets named [ServletDemo] and [com.vivizhang.servlet.ServletDemo] are both mapped to the url-pattern [/ServletDemo] which is not permitted

故事解决办法:

  可以选择删除web.

故事后续:

  当然,出现这个问题的原因肯定不止我这一个,肯定有其他原因,推荐还是参考下stackoverflow的吧,百度就算了,浪费时间。