故事由来:

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

故事梗概:

  学习servlet尽然能碰到服务器起不来的,百思不得其解,然后我百度,我翻墙google,找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文件后,代码中会生成如下一大块代码。

 import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Servlet implementation class ServletDemo
*/
@WebServlet("/ServletDemo")
public class ServletDemo extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public ServletDemo() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
} }

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

@WebServlet("/ServletDemo")

这个注解是eclipse帮我们生成好的,而问题恰恰就出在这。我们知道,每次我们新建一个servlet后会在web.xml文件中配置映射关系,这样才能在浏览器敲入一个地址后,地址发来的请求能让服务器接收到请求并将该请求交给指定的Servlet去处理。web.xml的作用就在此,它的代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<servlet>
<servlet-name>ServletDemo</servlet-name>
<servlet-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 start
java.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 more
Caused 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.WebXml.addServletMapping(WebXml.java:293)
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 startInternal
SEVERE: A child container failed during start
java.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 start
SEVERE: 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 more
Caused 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 more
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.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.xml中的映射,也可以选择将自动生成的注解注释掉,这样就不会有冲突了,二者选其一留下即可。

故事后续:

  如果在其他问题都没出错的情况下,可能就是xml文件和注解出现了冲突,当然,出现这个问题的原因不止这一个,会有其他很多原因,去google吧,希望我的文章能帮助你解决实际的问题。

Server Tomcat v7.0 Server at localhost failed to start.错误可能原因之一的更多相关文章

  1. Server Tomcat v7.0 Server at localhost failed to start.临时解决办法

    错误名:Server Tomcat v7.0 Server at localhost failed to start. 解决办法:去掉下面这句话: (通常在代码开头部分,public class前) ...

  2. eclipse中配置tomcat后,运行jsp时出现Server Tomcat v7.0 Server at localhost failed to start.

    最近在进行jsp开发学习,在配置上还是遇到很多问题. 在连接好数据库后,写了第一个jsp测试页面,结果在运行eclipse中运行toamcat时出现了错误提示:Server Tomcat v7.0 S ...

  3. Server Tomcat v7.0 Server at localhost failed to start解决办法

    今晚搞了下tomcat,在调试的时候发现报了这样一个错误Server Tomcat v7.0 Server at localhost failed to start 首先,确认了端口号8080是不是被 ...

  4. Android-67-Tomcat启动出错:Server Tomcat v7.0 Server at localhost failed to start.

     错误:Server Tomcat v7.0 Server at localhost failed to start.如图: 唉! ! !!图片上传不上去,悲哀啊!..仅仅能先写着错误提示语吧~~ ...

  5. 关于Tomcat无法启动的问题(Server Tomcat v7.0 Server at localhost failed to start.)

    我们在使用tomcat时会发生Server Tomcat v7.0 Server at localhost failed to start.即tomcat无法启动的问题,如下图:

  6. 【解决】Server Tomcat v7.0 Server at localhost failed to start.

    Server Tomcat v7.0 Server at localhost failed to start. 出现此原因是因为servlet-name不匹配 修改一致即可

  7. tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start.

    tomcat启动失败问题排除及解决办法 Server Tomcat v7.0 Server at localhost failed to start. 导致上面问题的原因可能有很多种,每种的解决办法都 ...

  8. Server Tomcat v7.0 Server at localhost failed to start.解决办法(图文详解)

    问题描述 Server Tomcat v7.0 Server at localhost failed to start. 解决办法 把你工作空间文件夹下的如下路径打开: <workspace-d ...

  9. web项目——启动时tomcat报错:Server Tomcat v7.0 Server at localhost failed to start.

    报错信息:Server Tomcat v7.0 Server at localhost failed to start. 报错截图: 原因分析:在使用SSM框架时,生成的mapping与系统配置文件不 ...

  10. Tomcat启动失败 提示Server Tomcat v7.0 Server at localhost failed to start.六种解决方法

    Tomcat启动失败,提示Server Tomcat v7.0 Server at localhost failed to start 在一次查看自己以前写过的项目中,运行tomcat失败,出现如图提 ...

随机推荐

  1. 自定义Camera综述(一般步骤、注意事项、遇到的难题<【内存溢出问题】>、像素参考)

    一般步骤: 1. 检查和访问Camera:创建代码来检查Camera和所申请访问的存在性: 2. 创建一个预览类:继承SurfaceView来创建一个Camera的预览类,并实现SurfaceHold ...

  2. cocosbuilder学习汇总

    目前与cocos2d-x-2.14版本对应的cocosbuilder版本为cocosbuilder-3,目前为alpha-5.稳定版本为cocosbuilder2.1,但与cocos2d-x不匹配(C ...

  3. VS2012编译可在WinXP兼容程序

    VS2012需要安装Update 1补丁 在Project的属性 选择 配置属性 - 常规 - 平台工具集 - Visual Studio 2012 - Windows XP (v110_xp) 在P ...

  4. 在JS和.NET中使用JSON (以及使用Linq to JSON定制JSON数据)

    转载原地址: http://www.cnblogs.com/mcgrady/archive/2013/06/08/3127781.html 阅读目录 JSON的两种结构 认识JSON字符串 在JS中如 ...

  5. MES生产日报存储过程

    USE [ScreenMonitor]GO/****** Object: StoredProcedure [dbo].[ImportProductForDay] Script Date: 04/11/ ...

  6. hibernate中session,HQL,持久化,一对多,多对一

    package com.hanqi.test; import java.util.Date; import java.util.List; import org.hibernate.Query; im ...

  7. 正整数的n次方求和

    引理: (Abel分部求和法) $$\sum_{k=1}^{n}a_{k}b_{k}=A_{n}b_{n}+\sum_{k=1}^{n-1}A_{k}(b_{k}-b_{k+1})$$其中$A_{k} ...

  8. python的random模块

    As an example of subclassing, the random module provides the WichmannHill class that implements an a ...

  9. windows服务控制类

    /// <summary> /// 服务调用控制 /// </summary> public class WinServiceController { /// <summ ...

  10. event级别设置Resumable Space Allocation

    每日一贴,今天的内容关键字为event级别                           设置Resumable Space Allocation 设置Resumable Space Alloc ...