Tomcat启动springboot项目war包报错:启动子级时出错的问题

首先,当我们将 SpringBoot 项目打包成 war 文件并上传到 Tomcat,启动时可能会出现以下错误提示:

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:173)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:153)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:95)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5128)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1025)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1895)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:824)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1601)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:928)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:456)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:107)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:88)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:409)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
    ... 10 common frames omitted
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229)
    at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43)
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:157)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:121)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:885)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:173)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:153)
    at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:95)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:171)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5128)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1025)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1895)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
    at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:824)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1601)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
    at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
    at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:928)
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:456)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:107)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:88)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:409)
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:174)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
    ... 10 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
    at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:436)
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:203)
    ... 54 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:461)
    at sun.nio.ch.Net.bind(Net.java:453)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:222)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:85)
    at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:228)
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:211)
    at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1141)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1154)
    at org.apache.tomcat.util.net.NioEndpoint.init(NioEndpoint.java:220)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:623)
    at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:68)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:1056)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:552)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:1059)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:136)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:173)
    ... 56 common frames omitted

这是因为 Tomcat 启动时端口被占用了。我们需要先关闭对应端口的进程,或者更改 Tomcat 的启动端口。

下面是两个示例:

  1. 找到占用 Tomcat 端口的进程 ID,然后关闭进程:
$ netstat -ano | grep "8080"
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      22377/java
$ kill -9 22377
  1. 更改 Tomcat 启动端口:

找到 <TomcatHome>/conf/server.xml 文件,修改以下内容:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

改成:

<Connector port="8888" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

重启 Tomcat 就行了。

希望能帮到你!

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Tomcat启动springboot项目war包报错:启动子级时出错的问题 - Python技术站

(0)
上一篇 2023年5月20日
下一篇 2023年5月20日

相关文章

  • JSP中图片的上传与显示方法实例详解

    下面就为大家详细讲解一下“JSP中图片的上传与显示方法实例详解”的完整攻略。 1. 确认上传的文件类型 在上传图片前,我们需要确认上传的文件类型,以防止一些不合法的文件被上传。可以通过以下代码片段实现: String fileName = fileItem.getName(); String extName = fileName.substring(file…

    Java 2023年6月15日
    00
  • 一步步教你整合SSM框架(Spring MVC+Spring+MyBatis)详细教程

    一步步教你整合SSM框架(Spring MVC+Spring+MyBatis)详细教程 什么是SSM框架? SSM框架是Spring MVC + Spring + MyBatis三个框架的组合。它们都是Java企业级应用程序开发中非常流行的框架。Spring MVC框架负责请求处理,Spring框架负责业务逻辑处理和依赖注入,MyBatis框架负责数据库操作…

    Java 2023年5月16日
    00
  • AOP之事务管理的两种配置方式

    对于AOP之事务管理的两种配置方式,我们可以使用以下两种方式进行配置: 一、使用标签配置事务管理 1. 在XML配置文件中声明TransactionManager代理 <!– 声明 TransactionManager bean –> <bean id="txManager" class="org.spri…

    Java 2023年5月20日
    00
  • JSP上传文件到指定位置实例代码

    下面我将详细讲解“JSP上传文件到指定位置实例代码”的完整攻略: 标题 JSP上传文件到指定位置实例代码 代码实现步骤 首先在 JSP 页面中使用 input 标签设置一个文件上传表单: <form action="upload.jsp" method="post" enctype="multipart…

    Java 2023年6月15日
    00
  • 关于Java利用反射实现动态运行一行或多行代码

    Java反射是指通过运行时借助Java API获取对象信息的机制。反射允许我们在程序运行时动态获取类的相关信息、构造实例、调用方法、访问和修改字段属性等。在一些特殊的需求场景下,我们可以利用Java的反射机制来实现动态运行一行或多行代码。以下是具体实现步骤: 1. 获取指定类的Class对象 在Java中,所有的类都是对象,每个类都有一个Class对象。获取…

    Java 2023年5月26日
    00
  • 详解Spring Boot自动装配的方法步骤

    详解Spring Boot自动装配的方法步骤 Spring Boot是一个基于Spring框架的快速开发框架,它可以帮助我们快速构建Web应用程序。其中一个最重要的特性就是自动装配。在本攻略中,我们将详细讲解Spring Boot自动装配的方法步骤。 什么是自动装配 自动装配是Spring Boot的一个重要特性,它可以帮助我们自动配置应用程序。在自动装配过…

    Java 2023年5月14日
    00
  • Java序列化的作用是什么?

    Java序列化是指将Java对象转换为字节流的过程,以便将其存储在文件中、在网络上传输或将其传递给其他进程。Java序列化的作用是可以在不同的系统和平台之间传输对象,使其具有通用性和可重用性。 在Java中,我们可以使用Serializable接口将一个对象序列化为字节流,然后在需要时将其重新反序列化回到原始对象。以下是使用Java序列化的几个步骤: 实现可…

    Java 2023年5月11日
    00
  • java获取文件编码,jsoup获取html纯文本操作

    获取文件编码: 在使用Java查看文件的编码时,可以通过两种方式来获取文件的编码:使用Java内部库获取、使用第三方工具库获取。 使用Java内部库获取文件编码 Java内部库中,提供了获取文件编码的方式:使用InputStreamReader类的getEncoding()方法获取文件编码。以下是示例代码: public static String getF…

    Java 2023年5月19日
    00
合作推广
合作推广
分享本页
返回顶部