springboot使用外置tomcat报The required Server component failed to start so Tomcat is unable to start分析

java哥 阅读:142 2021-11-03 14:32:45 评论:0
本文章主要介绍了springboot使用外置tomcat报The required Server component failed to start so Tomcat is unable to start,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!

使用外置tomcat部署打包成war包的springboot项目时,报如下错误

28-Jun-2018 18:20:54.110 SEVERE [main] org.apache.catalina.startup.Catalina.start The required Server component failed to start so Tomcat is unable to start. 
 org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 
    at org.apache.catalina.startup.Catalina.start(Catalina.java:655) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:497) 
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355) 
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495) 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) 
    ... 7 more 
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) 
    ... 9 more 
Caused by: org.apache.catalina.LifecycleException: A child container failed during start 
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:921) 
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) 
    ... 11 more

解决方法:

在pom.xml里的以下依赖加上exclusions,原因:springboot内嵌tomcat,在使用外置的tomcat时,需要剔除本身自带的

<dependency> 
            <groupId>org.springframework.boot</groupId> 
            <artifactId>spring-boot-starter-web</artifactId> 
            <exclusions> 
                <exclusion> 
                    <groupId>org.springframework.boot</groupId> 
                    <artifactId>spring-boot-starter-tomcat</artifactId> 
                </exclusion> 
            </exclusions> 
        </dependency> 

MainApp继承SpringBootServletInitializer,实现如下代码:

public class MainApp extends SpringBootServletInitializer {
    
    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
        return builder.sources(MainApp.class); 
    } 
 
    public static void main(String[] args) { 
        SpringApplication.run(MainApp.class, args); 
    } 
} 

标签:Spring Boot
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号