今天在写Servlet程序时
本想运行测试一下
没想到竟然报错了
连启动服务器都失败了
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/javaweb]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
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:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/javaweb]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
... 21 more
Caused by: java.lang.IllegalArgumentException: 名为 [initparam]和 [javaweb.InitParamServlet] 的servlet不能映射为一个url模式(url-pattern) [/InitParamServlet]
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMappingDecoded(WebXml.java:342)
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2460)
at org.apache.catalina.startup.ContextConfig.processClass(ContextConfig.java:2136)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2125)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:2017)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:2011)
at org.apache.catalina.startup.ContextConfig.processClasses(ContextConfig.java:1234)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1143)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5048)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 27 more
九月 21, 2019 2:57:39 下午 org.apache.catalina.core.ContainerBase startInternal
严重: 子容器启动失败
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 子容器启动失败
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:932)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
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:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: org.apache.catalina.LifecycleException: 子容器启动失败
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:928)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
... 13 more
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/javaweb]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:916)
... 21 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/javaweb]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
... 21 more
Caused by: java.lang.IllegalArgumentException: 名为 [initparam]和 [javaweb.InitParamServlet] 的servlet不能映射为一个url模式(url-pattern) [/InitParamServlet]
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMappingDecoded(WebXml.java:342)
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2460)
at org.apache.catalina.startup.ContextConfig.processClass(ContextConfig.java:2136)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2125)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:2017)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:2011)
at org.apache.catalina.startup.ContextConfig.processClasses(ContextConfig.java:1234)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1143)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:775)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5048)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 27 more
九月 21, 2019 2:57:39 下午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["http-nio-8080"]
九月 21, 2019 2:57:39 下午 org.apache.coyote.AbstractProtocol pause
信息: Pausing ProtocolHandler ["ajp-nio-8009"]
九月 21, 2019 2:57:39 下午 org.apache.catalina.core.StandardService stopInternal
信息: Stopping service [Catalina]
九月 21, 2019 2:57:39 下午 org.apache.coyote.AbstractProtocol destroy
信息: 正在摧毁协议处理器 ["http-nio-8080"]
九月 21, 2019 2:57:39 下午 org.apache.coyote.AbstractProtocol destroy
信息: 正在摧毁协议处理器 ["ajp-nio-8009"]
严重: 子容器启动失败
java.util.concurrent.ExecutionException:
org.apache.catalina.LifecycleException: 子容器启动失败
Caused by: java.lang.IllegalArgumentException: 名为 [initparam]和
[javaweb.InitParamServlet] 的servlet不能映射
为一个url模式(url-pattern) [/InitParamServlet]
严重: 所必需的服务组件启动失败,所以无法启动Tomcat
org.apache.catalina.LifecycleException: 子容器启动失败
原因就是Tomcat启动组件启动失败导致子容器启动失败
名为 [initparam]和[javaweb.InitParamServlet] 的servlet不能映射为一个url模式(url-pattern) [/InitParamServlet]
问题应该是出在Servlet映射上了
搜了很久都没有有效的解决办法
之前的解释不太合理,这次测试过很多次了,没有问题
这还是后来几天学习过程中其他报错让我灵光一现想起这个报错来
现在来更新问题原因及解决办法
出现这种报错的原因就是:
如图为注解配置Servlet映射路径:
以下是我在web.xml文件里的对该Servlet配置信息:
initparam
javaweb.InitParamServlet
info
这是取得初始化参数的Servlet程序!
initparam
/InitParamServlet
很明显,二者重复配置了映射路径
这样一来也就能够理解Tomcat控制台的报错信息了:
严重: 子容器启动失败
java.util.concurrent.ExecutionException:
org.apache.catalina.LifecycleException: 子容器启动失败
Caused by: java.lang.IllegalArgumentException: 名为 [initparam]和
[javaweb.InitParamServlet] 的servlet不能映射
为一个url模式(url-pattern) [/InitParamServlet]
名为 [initparam]和[javaweb.InitParamServlet] 的servlet不能映射为一个url模式(url-pattern) [/InitParamServlet]
一个是注解配置的,一个是web.xml文件配置的,配置重复了,二者不能映射为一个url模式
服务器启动成功
【当!当!当!】从控制台的时间上可以看出,时隔5天终于把这个问题给搞明白了,虽然不是什么大成就,但毕竟通过自己摸索解决了问题,内心还是有点小激动的~
再运行Servlet:
运行成功了
【总结】通过注解可以对Servlet映射路径进行配置,通过web.xml文件也可以对Servlet映射路径进行配置,但两者都存在就会使映射路径出错,导致Tomcat服务器启动失败,就出现了开头的报错了:
Server Tomcat v9.0 Server at localhost failed to start.
【建议】通过注解配置和通过web.xml配置二者选其一即可,大多数都是用web.xml进行Servlet的配置,但是注解配置也的确非常方便。
【Java Web】相关技术文章:
【Java Web总结】Java Web项目中 的.classpath、.mymetadata、.project文件作用
【Java Web问题解决】Tomcat报错javax.servlet.ServletException: Error instantiating servlet class.报错404
【比较】什么是“服务器端跳转”“客户端跳转”,二者有什么区别?
【总结】表单提交的get和post有什么不同?
【Java Web问题解决】Tomcat报错:java.lang.ClassCastException: cannot be cast to javax.servlet.Filter解决办法
【Java Web问题解决】Filter过滤器初始化方法init()执行了两次原因及解决方法
【总结】Java Web 中的4种属性范围(page、request、session、application)
【Java Web问题解决】Tomcat报错:java.sql.SQLException: No suitable driver found for jdbc:mysql://
【Java Web问题解决】Tomcat启动时控制台出现中文乱码的问题解决方法
【示例项目】java实现通过身份证号码判断籍贯所在地区
【总结】HTTP协议中的状态码(200、403、404、500等)
【Java Web问题解决】提交表单后显示乱码
【Java Web总结】JSP页面的生命周期详解
【Java Web总结】JSP页面实现类详解
【Java Web 问题解决】Tomcat启动失败 报错:Server Tomcat v9.0 Server at localhost failed to start.
【Java Web问题解决】连接数据库出错:java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
【Linux 操作系统】相关技术文章:
【Linux问题解决】Ubuntu Linux 安装gcc4.9 g++4.9报错“没有可供安装的候选者”解决办法
【Linux教程】Ubuntu Linux 更换源教程
【Linux教程】如何实现在Ubuntu Linux和windows之间复制粘贴、拖拽复制文件?
【Linux问题解决】操作系统用C语言多线程编程 对‘pthread_create’未定义的引用 报错解决办法
【Linux教程】Linux中用C语言多线程编程之pthread_join()函数
【Linux操作系统、C语言】在Linux中用C语言进行OpenMP并行程序设计之常见指令、库函数和指令总结