简体   繁体   English

Tomcat 8 Embedded-WebServlet-'子容器在启动期间失败'

[英]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.xmlpom.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.xmlpom.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: 如果我对INFOSEVERE 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: 如果发现某些依赖项会产生冲突,则可以通过两种方式工作:

  1. Remove o replace the dependency (Ex. jetty, camel). 删除o替换依赖项(例如码头,骆驼)。
  2. Mark the dependency like provided, that means that will be use for the jar in the point number 1. 像提供的那样标记依赖项,这意味着将在点1中使用该jar。

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.

相关问题 Tomcat 7“严重:启动期间子容器失败” - Tomcat 7 “SEVERE: A child container failed during start” Tomcat 8 嵌入式 - 错误 {org.apache.catalina.core.ContainerBase} - 子容器在启动过程中失败 - Tomcat 8 embedded - ERROR {org.apache.catalina.core.ContainerBase} - A child container failed during start Eclipse中的Apache Tomcat 7无法启动:子容器在启动期间失败 - Apache Tomcat 7 in Eclipse fails to start: A child container failed during start Tomcat 8 抛出错误:“启动期间子容器失败” - Tomcat 8 throws error : 'A child container failed during start' Tomcat Maven 插件 - 子容器在启动过程中失败 - Tomcat Maven Plugin - A child container failed during start 子容器在启动期间失败(Apache Tomcat 8.5 不再工作) - A child container failed during start(Apache Tomcat 8.5 not working anymore) Tomcat V8无法在Eclipse中启动-严重:启动期间子容器失败 - Tomcat V8 doesn't start in Eclipse - SEVERE: A child container failed during start 抛出mvn tomcat7:run命令严重:子容器在启动过程中失败 - mvn tomcat7:run command thrown SEVERE: A child container failed during start Tomcat v7.0 在启动期间不起作用(子容器在启动期间失败 java.util.concurrent.ExecutionException) - Tomcat v7.0 is not working during the start (A child container failed during start java.util.concurrent.ExecutionException) 子容器在j2ee tomcat中启动java.util.concurrent.ExecutionException期间失败 - A child container failed during start java.util.concurrent.ExecutionException in j2ee tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM