无法启动 bean 'webServerStartStop';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web
Posted
技术标签:
【中文标题】无法启动 bean \'webServerStartStop\';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web【英文标题】:Failed to start bean 'webServerStartStop'; Unable to start embedded Tomcat server - spring-boot-starter-web无法启动 bean 'webServerStartStop';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web 【发布时间】:2021-05-25 06:56:49 【问题描述】:使用仅包含 Spring Web 依赖的 Maven 的 Spring 应用程序会出现“无法启动嵌入式 Tomcat 服务”错误。
同样的项目可以像预期的那样在其他计算机上运行。
Spring Boot 版本:2.4.3 封装类型:JAR Java 版本:11
除了打印到控制台进行测试外,没有从启动项目添加其他代码。
当 tomcat 被排除在 pom.xml 中时,应用程序运行并打印到控制台,就像预期的那样。 测试了多个端口。 经过测试的 JDK 8 和 11。pom.xml 依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
日志:
2021-02-22 16:17:28.896 INFO 34556 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication using Java 11.0.10 on Soul with PID 34556 (C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo\target\classes started by ryne0 in C:\Users\ryne0\Desktop\FullStackWeb\Spring\demo)
2021-02-22 16:17:28.900 INFO 34556 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-02-22 16:17:28.902 DEBUG 34556 --- [ main] o.s.boot.SpringApplication : Loading source class com.example.demo.DemoApplication
2021-02-22 16:17:28.995 DEBUG 34556 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@457c9034
2021-02-22 16:17:30.317 DEBUG 34556 --- [ main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [ main] .s.b.w.e.t.TomcatServletWebServerFactory : Code archive: C:\Users\ryne0\.m2\repository\org\springframework\boot\spring-boot\2.4.3\spring-boot-2.4.3.jar
2021-02-22 16:17:30.318 DEBUG 34556 --- [ main] .s.b.w.e.t.TomcatServletWebServerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2021-02-22 16:17:30.353 INFO 34556 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 81 (http)
2021-02-22 16:17:30.374 INFO 34556 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-22 16:17:30.387 INFO 34556 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-22 16:17:30.507 INFO 34556 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-22 16:17:30.507 DEBUG 34556 --- [ main] w.s.c.ServletWebServerApplicationContext : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2021-02-22 16:17:30.508 INFO 34556 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1513 ms
2021-02-22 16:17:30.535 DEBUG 34556 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
2021-02-22 16:17:30.547 DEBUG 34556 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2021-02-22 16:17:30.599 DEBUG 34556 --- [ main] o.s.b.w.s.f.OrderedRequestContextFilter : Filter 'requestContextFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [ main] s.b.w.s.f.OrderedCharacterEncodingFilter : Filter 'characterEncodingFilter' configured for use
2021-02-22 16:17:30.600 DEBUG 34556 --- [ main] o.s.b.w.s.f.OrderedFormContentFilter : Filter 'formContentFilter' configured for use
2021-02-22 16:17:30.817 INFO 34556 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:30.828 DEBUG 34556 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2021-02-22 16:17:30.949 DEBUG 34556 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2021-02-22 16:17:30.991 DEBUG 34556 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2021-02-22 16:17:31.003 DEBUG 34556 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2021-02-22 16:17:31.104 WARN 34556 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2021-02-22 16:17:31.110 INFO 34556 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2021-02-22 16:17:31.122 INFO 34556 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-02-22 16:17:31.197 DEBUG 34556 --- [ main] ConditionEvaluationReportLoggingListener :
2021-02-22 16:17:32.117 ERROR 34556 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.4.jar:5.3.4]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:934) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:585) ~[spring-context-5.3.4.jar:5.3.4]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) ~[spring-boot-2.4.3.jar:2.4.3]
at com.example.demo.DemoApplication.main(DemoApplication.java:10) ~[classes/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.4.jar:5.3.4]
... 15 common frames omitted
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:244) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) ~[spring-boot-2.4.3.jar:2.4.3]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) ~[spring-boot-2.4.3.jar:2.4.3]
... 17 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:240) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
... 19 common frames omitted
Caused by: java.io.IOException: Unable to establish loopback connection
at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:94) ~[na:na]
at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:61) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(Native Method) ~[na:na]
at java.base/sun.nio.ch.PipeImpl.<init>(PipeImpl.java:171) ~[na:na]
at java.base/sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:50) ~[na:na]
at java.base/java.nio.channels.Pipe.open(Pipe.java:155) ~[na:na]
at java.base/sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:142) ~[na:na]
at java.base/sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:44) ~[na:na]
at java.base/java.nio.channels.Selector.open(Selector.java:295) ~[na:na]
at org.apache.tomcat.util.net.NioselectorPool.getSharedSelector(NioSelectorPool.java:52) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.NioSelectorPool.close(NioSelectorPool.java:119) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:386) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1198) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1279) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:608) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1071) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
... 21 common frames omitted
Caused by: java.net.BindException: Cannot assign requested address: connect
at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:476) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:468) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:694) ~[na:na]
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:194) ~[na:na]
at java.base/sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(PipeImpl.java:127) ~[na:na]
at java.base/sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:76) ~[na:na]
... 36 common frames omitted
【问题讨论】:
也许这个对类似问题的回答应该对你有所帮助:***.com/a/18007598/10263562 【参考方案1】:为个人网络接口控制器 (NIC) 安装了控制软件,允许同时使用以太网和 wifi。据说这是为了改善游戏体验而安装的,但在 Spring 中不能很好地与 tomcat 配合使用。禁用后,应用程序就可以按预期运行。
【讨论】:
【参考方案2】:在将 server.port 从 80 更改为 8080 后,它为我修复了。
【讨论】:
以上是关于无法启动 bean 'webServerStartStop';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web的主要内容,如果未能解决你的问题,请参考以下文章
Springboot 2.6.0 / Spring fox 3 - 无法启动 bean 'documentationPluginsBootstrapper'
由于 Bean Validation API 无法启动 Hibernate Validator
spring boot 无法启动——在配置中定义一个“TopicRepository”类型的bean
Spring Boot 错误:由于缺少 EmbeddedServletContainerFactory bean,无法启动 EmbeddedWebApplicationContext
由于缺少 ServletWebServerFactory bean,即使使用 @springbootapplication,我也无法启动 ServletWebServerApplicationCont