[英]Tomcat 8 Embedded - WebServlet - 'A child container failed during start'
I have an embedded Tomcat server that is serving static files just fine. 我有一个嵌入式Tomcat服务器,可以很好地提供静态文件。 But when I add the buildPath code required to get @WebServlet
working, it doesn't work in one of my projects (there are plenty of differences between projects... about 50K lines worth). 但是,当我添加使@WebServlet
工作所需的buildPath代码时,它在我的一个项目中不起作用(项目之间有很多差异……价值约5万行)。
I get the following error before web.xml
is even read (I know this from strace -ff
). 在读取web.xml
之前,我得到以下错误(我从strace -ff
知道这一点)。
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:367)
at app.http.TomcatServer.startTomcat(TomcatServer.java:87)
at app.main.MainTools.startServer(MainTools.java:277)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 4 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 8 more
seemingly caused by this line: 似乎是由以下行引起的:
ctx.setResources(resources);
which is needed to make @WebServlet
work, as described here (indeed, WebServlet doesn't work without the setResources
, in any project. I and others have some working projects that use the setResources
). 这是需要做出@WebServlet
工作,如所描述这里 (实际上,WebServlet不无工作setResources
,在任何项目中,我和其他人使用的一些工作项目setResources
)。
strace
shows that Tomcat is looking for some files in META-INF: strace
显示Tomcat正在META-INF中寻找一些文件:
META-INF/services/java.nio.channels.spi.SelectorProvider
META-INF/services/javax.xml.parsers.SAXParserFactory
META-INF/services/org.apache.juli.logging.Log
While I don't have these files, I also have a working project that does not have these files, so they apparently are not required. 虽然我没有这些文件,但我还有一个工作项目,其中没有这些文件,因此显然不需要它们。 I tried creating that log file, because it looked like maybe Juli was trying to tell me something. 我尝试创建该日志文件,因为看起来Juli似乎想告诉我一些事情。 Alas, it opens the org.apache.juli.logging.Log
but writes nothing to it. las,它打开了org.apache.juli.logging.Log
但是没有写任何东西。
strace
also reveals that the main Tomcat thread (successfully) stat
s the following file right before printing the exception: strace
还显示,在打印异常之前,Tomcat主线程(成功) stat
s包含以下文件:
org/apache/catalina/core/ContainerBase$StartChild.class
Despite all of this activity, it's not stat
ing or looking inside WEB-INF in any way! 尽管所有这些活动,这不是stat
荷兰国际集团或以任何方式寻找WEB-INF里面! In fact, there are no accesses to any file named web.xml
or pom.xml
. 实际上,无法访问任何名为web.xml
或pom.xml
文件。
So all the various solutions involving changes to web.xml
or pom.xml
are irrelevant because Tomcat does not even open those files before generating the LifecycleException. 因此,涉及更改web.xml
或pom.xml
所有各种解决方案都是无关紧要的,因为Tomcat甚至在生成LifecycleException之前都不会打开这些文件。
While others have seen LifecycleException, it appears that this is a new context. 当其他人看到LifecycleException时,这似乎是一个新上下文。 For example, others have seen a different form of the exception which has a more helpful exception . 例如,其他人看到了异常的另一种形式,它具有更有用的异常 。 Still others are seeing a similar error in standalone Tomcat , but they have the luxury of $CATALINA logs. 还有一些人在独立的Tomcat中看到了类似的错误,但是它们拥有$ CATALINA日志的功能。 But I have not found other questions/solutions involving the above, very vague form of the exception in embedded Tomcat. 但是我还没有发现涉及嵌入式Tomcat中上述非常模糊形式的异常的其他问题/解决方案。
Also, I set the Java logging level to Level.ALL, and there is much output, but no obviously helpful information. 另外,我将Java日志记录级别设置为Level.ALL,并且有很多输出,但是没有明显有用的信息。 If I grep for INFO
and SEVERE
I get: 如果我对INFO
和SEVERE
grep, SEVERE
得到:
2018.02.26 10:25:39.226 INFO: Initializing ProtocolHandler ["http-nio-8081"]
2018.02.26 10:25:39.241 INFO: Using a shared selector for servlet write/read
2018.02.26 10:25:39.249 INFO: Starting service [Tomcat]
2018.02.26 10:25:39.250 INFO: Starting Servlet Engine: Apache Tomcat/8.5.24
2018.02.26 10:25:39.309 SEVERE: A child container failed during start
2018.02.26 10:25:39.309 SEVERE: A child container failed during start
2018.02.26 10:25:39.312 SEVERE: Failed to start component [StandardServer[-1]]
2018.02.26 10:25:43.485 INFO: Starting shutdown.
2018.02.26 10:25:43.486 INFO: Starting shutdown.
Is there maybe some way I can enable better logging, or maybe call something in Tomcat to have it tell me about all these .jar etc. searches it's trying to do? 是否有某种方法可以启用更好的日志记录,或者在Tomcat中调用某些内容以使它告诉我它正在尝试执行的所有这些.jar等内容?
Please help. 请帮忙。 I am new to Tomcat embedded. 我是Tomcat嵌入式的新手。
You need to combine two solutions: 您需要结合两种解决方案:
First of all, validate the mvn dependency:tree
, this can list all dependencies that you have associate with this specific jar servlet-api:jar
. 首先,验证mvn dependency:tree
,它可以列出您与此特定jar servlet-api:jar
相关联的所有依赖项。
If you find some dependency that is producing some conflict you can work in two ways: 如果发现某些依赖项会产生冲突,则可以通过两种方式工作:
Is so clear that the second options can be the best, but sometimes you need to clean ups your dependencies. 非常清楚,第二个选项可能是最好的,但是有时您需要清理依赖项。
Note: Be sure that you are using the correct version and Id of the dependency that is listed in the mvn dependency:tree
. 注意:确保您使用的是mvn dependency:tree
列出的依赖项的正确版本和ID。
`<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>`
The mvn dependency:tree
should produce: mvn dependency:tree
应该产生:
`+- javax.servlet:javax.servlet-api:jar:3.0.1:provided (scope not updated to
compile)`
This only one kind of exception that can produce a jar conflict inside of the container, in this case servlet-api.jar
. 这只是一种可能在容器内部产生jar冲突的异常,在本例中为servlet-api.jar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.