Tomcat 8 Embedded - WebServlet - '启动时子容器失败' [英] Tomcat 8 Embedded - WebServlet - 'A child container failed during start'

查看:2510
本文介绍了Tomcat 8 Embedded - WebServlet - '启动时子容器失败'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入式Tomcat服务器正常提供静态文件。但是当我添加 buildPath代码时要求 @WebServlet 工作,它在我的一个项目中不起作用(项目之间存在很多差异......大约50K行值) 。

I have an embedded Tomcat server that is serving static files just fine. 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).

我甚至在 web.xml 之前得到以下错误(我从<$ c $中知道这一点c> strace -ff )。

I get the following error before web.xml is even read (I know this from 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

看似由此行引起:

ctx.setResources(resources);

这需要使 @WebServlet 工作,如此处所述(事实上,没有 setResources ,在任何项目中。我和其他人有一些使用 setResources 的工作项目。

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).

strace 显示Tomcat正在寻找META-INF中的一些文件:

strace shows that Tomcat is looking for some files in 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

虽然我没有这些文件,但我也有一个没有这些文件的工作项目,所以他们显然不是必需的。我试着创建那个日志文件,因为看起来好像Juli试图告诉我一些事情。唉,它会打开 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. Alas, it opens the org.apache.juli.logging.Log but writes nothing to it.

strace 还会在打印异常之前显示主Tomcat线程(成功) stat s以下文件:

strace also reveals that the main Tomcat thread (successfully) stats the following file right before printing the exception:

org/apache/catalina/core/ContainerBase$StartChild.class

尽管所有这些活动,但它不是 stat 以任何方式查看或查看WEB-INF!实际上,没有访问任何名为 web.xml pom.xml 的文件。

Despite all of this activity, it's not stating or looking inside WEB-INF in any way! In fact, there are no accesses to any file named web.xml or pom.xml.

因此所有涉及 web.xml 的变更的各种解决方案 pom.xml 无关紧要,因为Tomcat甚至在生成LifecycleException之前都没有打开这些文件。

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.

虽然其他人看到了LifecycleException,但似乎是s是一个新的背景。例如,其他人已经看到了一种不同形式的例外,其中一个更有用的例外。还有一些人在独立的Tomcat 中看到了类似的错误,但他们拥有$ CATALINA日志的奢侈品。 但我还没有找到涉及上述其他问题/解决方案,在嵌入式Tomcat中非常模糊的异常形式。

While others have seen LifecycleException, it appears that this is a new context. 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. But I have not found other questions/solutions involving the above, very vague form of the exception in embedded Tomcat.

另外,我设置了Java日志级别为Level.ALL,并且有很多输出,但没有明显有用的信息。如果我grep INFO SEVERE 我得到:

Also, I set the Java logging level to Level.ALL, and there is much output, but no obviously helpful information. If I grep for INFO and SEVERE I get:

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.

是否有某些方法可以启用更好的日志记录,或者可以在Tomcat中调用某些内容来告诉它我关于所有这些.jar等搜索它试图做什么?

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嵌入式的新手。

Please help. I am new to Tomcat embedded.

推荐答案

您需要结合两种解决方案:

You need to combine two solutions:

首先,验证 mvn依赖:tree ,这可以列出与此特定jar关联的所有依赖项 servlet-api :jar

First of all, validate the mvn dependency:tree, this can list all dependencies that you have associate with this specific jar servlet-api:jar.

如果你发现某些依赖会产生一些冲突,你可以用两种方式工作:

If you find some dependency that is producing some conflict you can work in two ways:


  1. 删除o替换依赖项(例如jetty,camel)。

  2. 标记依赖提供,这意味着将使用对于点数为1的罐子。

很清楚,第二个选项可能是最好的,但有时你需要清理你的依赖关系。

Is so clear that the second options can be the best, but sometimes you need to clean ups your dependencies.

注意:确保使用 mvn依赖关系中列出的依赖关系的正确版本和Id:树

`<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
</dependency>`

mvn依赖项:树应该产生:

`+- javax.servlet:javax.servlet-api:jar:3.0.1:provided (scope not updated to 
compile)`

这只是一种可能在容器内部产生jar冲突的异常,在本例中为 servlet-api.jar

This only one kind of exception that can produce a jar conflict inside of the container, in this case servlet-api.jar.

这篇关于Tomcat 8 Embedded - WebServlet - '启动时子容器失败'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆