tomcat java spring问题:服务器无法启动,因为“严重:子容器在启动时失败..."?

chhkpiq4  于 2022-12-19  发布在  Java
关注(0)|答案(2)|浏览(178)

我正在学习java的Spring Boot ,这是我的问题。
我决定这样整理我的文件

/layouts/user/footer.jsp
/layouts/user/header.jsp
/layouts/user.jsp
/user/index.jsp
/web.xml

我从user.jsp文件编写了以下代码,以链接到footer.jsp和header.jsp文件

<%@include file="/WEB-INF/views/layouts/user/header.jsp"%>
<decorator:body />
<%@include file="/WEB-INF/views/layouts/user/footer.jsp"%>

然后我用tomcat9.0.62运行我的代码,得到了这个错误

SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: 
Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/DemoSpringMVC]]
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Caused by: org.apache.catalina.LifecycleException: Failed to start component 
[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/DemoSpringMVC]]
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:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
... 21 more
Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name [sitemesh]
at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:3067)
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:3029)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1453)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1329)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 27 more
thg 12 18, 2022 4:56:35 CH org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:938)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
... 13 more
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/DemoSpringMVC]]
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:926)
... 21 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/DemoSpringMVC]]
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:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
... 21 more
Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name [sitemesh]
at 
org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:3067)
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:3029)
at 
org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1453)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1329)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:986)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:303)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5135)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 27 more

我尝试安装Tomcat 8.5和Tomcat 10,仍然遇到同样的错误,所以可能不是因为Tomcat版本。
我也引用了这个链接https://www.youtube.com/watch?v=bYMrMAi95YU,但是在我的代码中,我已经将代码更改为url-pattern,所以这不是原因。
这是我的代码,如果你需要

https://github.com/nguyencuc2586/Spring3.2

你能给予我一些建议吗?谢谢。

zynd9foi

zynd9foi1#

您已经将过滤器和servlet命名为“demo-config”。只需更新过滤器名称(观察filter-name标记中的值)

<filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
        </filter-class>
        <!-- Added the context configuration below -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/demo-config-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </filter>
sauutmhj

sauutmhj2#

我会说你需要首先注意输出异常栈。它已经提到了根本原因,即,“* 引起的:java.lang.非法参数异常:筛选器Map指定了未知的筛选器名称[sitemesh]*"。
如果你正在设置一个新的网络应用程序,我建议你也尽量简化它。所以,删除那些你不需要的过滤器。
如果您的Web应用程序之前运行成功,那么请关注您的新更改,特别是关于上述过滤器。
在github中检查了你的代码之后,我觉得你需要在“filter”和“filter-mapping”中设置同名的过滤器“sitemesh”,否则,filter-mapping将无法理解过滤器示例的位置。请尝试以下配置。注意:我将“过滤器名称”从“演示配置”更改为“站点网”。

<filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
        </filter-class>
        <!-- Added the context configuration below -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/demo-config-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </filter>

    <!-- Mapped the servlet to '/' -->
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

相关问题