在学习springCloud时发现这个错误
在启动Eureka注册中心EurekaApplication时报错如下:
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: A child container failed during start
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_141]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_141]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:878) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:249) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:428) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:914) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:481) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) [spring-context-5.3.27.jar:5.3.27]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) [spring-boot-2.7.12.jar:2.7.12]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) [spring-boot-2.7.12.jar:2.7.12]
at org.example.EurekaApplication.main(EurekaApplication.java:11) [classes/:na]
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:890) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:795) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_141]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_141]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
... 21 common frames omitted
Caused by: java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_141]
at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_141]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:878) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
... 29 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [NonLoginAuthenticator[StandardEngine[Tomcat].StandardHost[localhost].TomcatEmbeddedContext[]]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:171) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4864) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_141]
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) ~[na:1.8.0_141]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:871) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
... 29 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1201) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [tomcat-embed-core-9.0.75.jar:9.0.75]
... 39 common frames omitted
解决:
在spring-cloud-starter-netflix-eureka-server的依赖下面加入
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
加入依赖格式如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
然后再启动EurekaApplication就成功了