分析unable to start embedded tomcat
近期研习微服务相关知识的过程中出现了unable to start embedded tomcat的问题,网上查询了一些相关的解决方式,仍然无法解决,通过比对学习的项目的相关配置,才解决了这个问题
问题产生过程
在学习微服务知识时想要自己搭建一个eurekaserver,使用工具spring tool suite4,通过maven创建父工程 parent工程,pom.xml配置如下
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.2.5.release</version> <relativepath/> <!-- lookup parent from repository --> </parent> <groupid>com.springcloud</groupid> <artifactid>parent</artifactid> <version>0.0.1-snapshot</version> <packaging>pom</packaging> <description>springcloud</description> <properties> <java.version>1.8</java.version> </properties> <!--引入springcloud的版本--> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-dependencies</artifactid> <version>hoxton.sr3</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
eurekaserver 服务端的相关配置
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>com.springcloud</groupid> <artifactid>parent</artifactid> <version>0.0.1-snapshot</version> </parent> <artifactid>eureka_server</artifactid> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-netflix-eureka-server</artifactid> </dependency> <!--加入安全配置依赖的jar包--> <!-- <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-security</artifactid> </dependency>--> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
eurekaserver - application.properties文件配置
#eureka服务端应用的端口默认是8761 server.port=9001 #表示是否将自己注册到eureka server,默认为true,由于当前应用就是eureka server,故而设为false eureka.client.register-with-eureka=false # 表示是否从eureka server获取注册信息,默认为true,因为这是一个单点的eureka server,不需要同步其他的eureka server节点的数据,故而设为false eureka.client.fetch-registry=false eureka.client.service-url.defaultzone: http://localhost:9001/eureka/
服务在启动过程中出现了下面的报错
java.lang.exceptionininitializererror: null at com.thoughtworks.xstream.xstream.setupconverters(xstream.java:990) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.xstream.<init>(xstream.java:593) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.xstream.<init>(xstream.java:515) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.xstream.<init>(xstream.java:484) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.xstream.<init>(xstream.java:430) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.xstream.<init>(xstream.java:397) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.netflix.discovery.converters.xmlxstream.<init>(xmlxstream.java:51) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.converters.xmlxstream.<clinit>(xmlxstream.java:42) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.converters.wrappers.codecwrappers$xstreamxml.<init>(codecwrappers.java:358) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.converters.wrappers.codecwrappers.create(codecwrappers.java:133) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.converters.wrappers.codecwrappers.getencoder(codecwrappers.java:75) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.converters.wrappers.codecwrappers.getencoder(codecwrappers.java:66) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.provider.discoveryjerseyprovider.<init>(discoveryjerseyprovider.java:77) ~[eureka-client-1.9.17.jar:1.9.17] at com.netflix.discovery.provider.discoveryjerseyprovider.<init>(discoveryjerseyprovider.java:64) ~[eureka-client-1.9.17.jar:1.9.17] at java.base/jdk.internal.reflect.nativeconstructoraccessorimpl.newinstance0(native method) ~[na:na] at java.base/jdk.internal.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:78) ~[na:na] at java.base/jdk.internal.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) ~[na:na] at java.base/java.lang.reflect.constructor.newinstancewithcaller(constructor.java:499) ~[na:na] at java.base/java.lang.reflect.reflectaccess.newinstance(reflectaccess.java:128) ~[na:na] at java.base/jdk.internal.reflect.reflectionfactory.newinstance(reflectionfactory.java:350) ~[na:na] at java.base/java.lang.class.newinstance(class.java:642) ~[na:na] at com.sun.jersey.core.spi.component.componentconstructor._getinstance(componentconstructor.java:193) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.componentconstructor.getinstance(componentconstructor.java:180) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.providerfactory.__getcomponentprovider(providerfactory.java:166) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.providerfactory._getcomponentprovider(providerfactory.java:159) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.providerfactory.getcomponentprovider(providerfactory.java:153) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.providerservices.getcomponent(providerservices.java:278) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.component.providerservices.getproviders(providerservices.java:151) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.factory.messagebodyfactory.initreaders(messagebodyfactory.java:175) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.core.spi.factory.messagebodyfactory.init(messagebodyfactory.java:162) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl._initiate(webapplicationimpl.java:1338) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl.access$700(webapplicationimpl.java:180) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl$13.f(webapplicationimpl.java:799) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl$13.f(webapplicationimpl.java:795) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.spi.inject.errors.processwitherrors(errors.java:193) ~[jersey-core-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:795) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.server.impl.application.webapplicationimpl.initiate(webapplicationimpl.java:790) ~[jersey-server-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.servletcontainer.initiate(servletcontainer.java:509) ~[jersey-servlet-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.servletcontainer$internalwebcomponent.initiate(servletcontainer.java:339) ~[jersey-servlet-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.webcomponent.load(webcomponent.java:605) ~[jersey-servlet-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.webcomponent.init(webcomponent.java:207) ~[jersey-servlet-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:394) ~[jersey-servlet-1.19.1.jar:1.19.1] at com.sun.jersey.spi.container.servlet.servletcontainer.init(servletcontainer.java:744) ~[jersey-servlet-1.19.1.jar:1.19.1] at org.apache.catalina.core.applicationfilterconfig.initfilter(applicationfilterconfig.java:270) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.applicationfilterconfig.<init>(applicationfilterconfig.java:106) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardcontext.filterstart(standardcontext.java:4533) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5172) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:183) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1384) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1374) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.util.concurrent.futuretask.run(futuretask.java:264) ~[na:na] at org.apache.tomcat.util.threads.inlineexecutorservice.execute(inlineexecutorservice.java:75) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.util.concurrent.abstractexecutorservice.submit(abstractexecutorservice.java:145) ~[na:na] at org.apache.catalina.core.containerbase.startinternal(containerbase.java:909) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardhost.startinternal(standardhost.java:841) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:183) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1384) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.containerbase$startchild.call(containerbase.java:1374) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.util.concurrent.futuretask.run(futuretask.java:264) ~[na:na] at org.apache.tomcat.util.threads.inlineexecutorservice.execute(inlineexecutorservice.java:75) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at java.base/java.util.concurrent.abstractexecutorservice.submit(abstractexecutorservice.java:145) ~[na:na] at org.apache.catalina.core.containerbase.startinternal(containerbase.java:909) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardengine.startinternal(standardengine.java:262) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:183) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardservice.startinternal(standardservice.java:421) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:183) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.core.standardserver.startinternal(standardserver.java:930) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:183) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.apache.catalina.startup.tomcat.start(tomcat.java:467) ~[tomcat-embed-core-9.0.31.jar:9.0.31] at org.springframework.boot.web.embedded.tomcat.tomcatwebserver.initialize(tomcatwebserver.java:107) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatwebserver.<init>(tomcatwebserver.java:88) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatservletwebserverfactory.gettomcatwebserver(tomcatservletwebserverfactory.java:438) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatservletwebserverfactory.getwebserver(tomcatservletwebserverfactory.java:191) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.createwebserver(servletwebserverapplicationcontext.java:180) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.onrefresh(servletwebserverapplicationcontext.java:153) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:544) ~[spring-context-5.2.4.release.jar:5.2.4.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.refresh(servletwebserverapplicationcontext.java:141) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.refresh(springapplication.java:747) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.refreshcontext(springapplication.java:397) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:315) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:1226) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:1215) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at eureka_server.eurekaserverapplication.main(eurekaserverapplication.java:11) ~[classes/:na] caused by: java.lang.reflect.inaccessibleobjectexception: unable to make field private final java.util.comparator java.util.treemap.comparator accessible: module java.base does not "opens java.util" to unnamed module @74d1dc36 at java.base/java.lang.reflect.accessibleobject.checkcansetaccessible(accessibleobject.java:357) ~[na:na] at java.base/java.lang.reflect.accessibleobject.checkcansetaccessible(accessibleobject.java:297) ~[na:na] at java.base/java.lang.reflect.field.checkcansetaccessible(field.java:177) ~[na:na] at java.base/java.lang.reflect.field.setaccessible(field.java:171) ~[na:na] at com.thoughtworks.xstream.core.util.fields.locate(fields.java:40) ~[xstream-1.4.11.1.jar:1.4.11.1] at com.thoughtworks.xstream.converters.collections.treemapconverter.<clinit>(treemapconverter.java:50) ~[xstream-1.4.11.1.jar:1.4.11.1] ... 83 common frames omitted [2m2021-08-01 21:51:33.414[0;39m [31merror[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.standardcontext [0;39m [2m:[0;39m one or more filters failed to start. full details will be found in the appropriate container log file [2m2021-08-01 21:51:33.414[0;39m [31merror[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.standardcontext [0;39m [2m:[0;39m context [] startup failed due to previous errors [2m2021-08-01 21:51:33.419[0;39m [33m warn[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.loader.webappclassloaderbase [0;39m [2m:[0;39m the web application [root] appears to have started a thread named [spring.cloud.inetutils] but has failed to stop it. this is very likely to create a memory leak. stack trace of thread: java.base@16.0.1/jdk.internal.misc.unsafe.park(native method) java.base@16.0.1/java.util.concurrent.locks.locksupport.park(locksupport.java:341) java.base@16.0.1/java.util.concurrent.locks.abstractqueuedsynchronizer$conditionnode.block(abstractqueuedsynchronizer.java:505) java.base@16.0.1/java.util.concurrent.forkjoinpool.managedblock(forkjoinpool.java:3137) java.base@16.0.1/java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject.await(abstractqueuedsynchronizer.java:1614) java.base@16.0.1/java.util.concurrent.linkedblockingqueue.take(linkedblockingqueue.java:435) java.base@16.0.1/java.util.concurrent.threadpoolexecutor.gettask(threadpoolexecutor.java:1056) java.base@16.0.1/java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1116) java.base@16.0.1/java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:630) java.base@16.0.1/java.lang.thread.run(thread.java:831) [2m2021-08-01 21:51:33.496[0;39m [32m info[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.standardservice [0;39m [2m:[0;39m stopping service [tomcat] [2m2021-08-01 21:51:33.498[0;39m [33m warn[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mconfigservletwebserverapplicationcontext[0;39m [2m:[0;39m exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.applicationcontextexception: unable to start web server; nested exception is org.springframework.boot.web.server.webserverexception: unable to start embedded tomcat [2m2021-08-01 21:51:33.511[0;39m [32m info[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mconditionevaluationreportlogginglistener[0;39m [2m:[0;39m error starting applicationcontext. to display the conditions report re-run your application with 'debug' enabled. [2m2021-08-01 21:51:33.513[0;39m [31merror[0;39m [35m17088[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.boot.springapplication [0;39m [2m:[0;39m 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:156) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:544) ~[spring-context-5.2.4.release.jar:5.2.4.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.refresh(servletwebserverapplicationcontext.java:141) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.refresh(springapplication.java:747) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.refreshcontext(springapplication.java:397) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:315) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:1226) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.springapplication.run(springapplication.java:1215) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at eureka_server.eurekaserverapplication.main(eurekaserverapplication.java:11) ~[classes/:na] caused by: org.springframework.boot.web.server.webserverexception: unable to start embedded tomcat at org.springframework.boot.web.embedded.tomcat.tomcatwebserver.initialize(tomcatwebserver.java:126) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatwebserver.<init>(tomcatwebserver.java:88) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatservletwebserverfactory.gettomcatwebserver(tomcatservletwebserverfactory.java:438) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatservletwebserverfactory.getwebserver(tomcatservletwebserverfactory.java:191) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.createwebserver(servletwebserverapplicationcontext.java:180) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.servlet.context.servletwebserverapplicationcontext.onrefresh(servletwebserverapplicationcontext.java:153) ~[spring-boot-2.2.5.release.jar:2.2.5.release] ... 8 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:171) ~[spring-boot-2.2.5.release.jar:2.2.5.release] at org.springframework.boot.web.embedded.tomcat.tomcatwebserver.initialize(tomcatwebserver.java:110) ~[spring-boot-2.2.5.release.jar:2.2.5.release] ... 13 common frames omitted
从网上其他的文章分析来看-开始分析是由于相同一个maven repository造成的冲突,于是重新新建了一个repository 改了setting.xml配置,重新maven,启动还是报一样的错,仔细分析后,看到jre编译环境有所不同,开始下载sts之后一直没有改变过环境也是采用默认的jre
后面换成本地jdk1.8.0_251之后启动正常,打开eureka管理中心也是可以打开
此文章不一定适用所有人,但也为此问题提供了一个解决方法,如有瑕疵,往请见谅
以上就是解决“unable to start embedded tomcat“错误的完整指南的详细内容,更多关于unable to start embedded tomcat的资料请关注代码网其它相关文章!
发表评论