【问题标题】:spring boot Unable to start embedded Tomcatspring boot 无法启动嵌入式Tomcat
【发布时间】:2021-06-08 07:13:10
【问题描述】:

我是一名学生,我正在为考试做一个 Spring Boot 应用程序。我已经创建了在课堂上看到的实体、存储库、服务和控制器。然而,当我尝试启动我的应用程序时,我收到一个关于嵌入 tomcat 的错误。

我正在附加堆栈跟踪:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-08 08:59:40.768 ERROR 42228 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

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:163) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.7.jar:5.3.7]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:337) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1336) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1325) ~[spring-boot-2.5.0.jar:2.5.0]
    at com.example.fast_food.FastFoodApplication.main(FastFoodApplication.java:12) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.5.0.jar:2.5.0]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:450) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:199) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[spring-boot-2.5.0.jar:2.5.0]
    ... 13 common frames omitted
Caused by: java.lang.IllegalStateException: StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[] failed to start
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.rethrowDeferredStartupExceptions(TomcatWebServer.java:187) ~[spring-boot-2.5.0.jar:2.5.0]
    at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:126) ~[spring-boot-2.5.0.jar:2.5.0]
    ... 18 common frames omitted


Process finished with exit code 0

【问题讨论】:

  • 尝试创建一个spring boot jar并从命令行运行它,有时IDE和cmd行有不同的错误。这可能是因为 Spring Boot 中的 Configuration 类。
  • 请出示您的 pom.xml
  • 你能在启动你的应用程序时分享所有的输出吗?输出中应该有一些内容显示 Tomcat 无法启动的原因。

标签: java spring spring-boot web tomcat


【解决方案1】:

您的主要方法看起来如何,您能否发布您的依赖项?从堆栈跟踪来看,tomcat 无法启动可能有多种原因。

您可以尝试在 application.properties 中使用不同的服务器端口,即添加

server.port=8082

【讨论】:

    猜你喜欢
    • 2016-08-19
    • 2017-09-20
    • 1970-01-01
    • 2020-07-24
    • 2023-03-26
    • 2019-03-13
    • 2021-05-25
    • 2014-06-27
    • 2019-10-11
    相关资源
    最近更新 更多