SpringBoot + SpringCloud项目Eureka启动报错
本文内容纲要:
个人搭建SpringCloud项目,在搭建Eureka-service的时候,项目启动报错。Causedby:java.lang.ClassNotFoundException:org.springframework.cloud.context.environment.EnvironmentChangeEvent,具体的错误信息如下所示:
org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration':Unsatisfieddependencyexpressedthroughfield'eurekaServerBootstrap';nestedexceptionisorg.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'eurekaServerBootstrap'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'eurekaServerBootstrap'parameter1;nestedexceptionisorg.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'eurekaServerContext'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'eurekaServerContext'parameter2;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'peerEurekaNodes'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Post-processingofmergedbeandefinitionfailed;nestedexceptionisjava.lang.IllegalStateException:FailedtointrospectClass[org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration$RefreshablePeerEurekaNodes]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]
atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atorg.springframework.boot.SpringApplication.run(SpringApplication.java:327)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1255)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1243)[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
atcom.cloud.eureka.EurekaServiceApplication.main(EurekaServiceApplication.java:13)[classes/:na]
Causedby:org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'eurekaServerBootstrap'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'eurekaServerBootstrap'parameter1;nestedexceptionisorg.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'eurekaServerContext'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'eurekaServerContext'parameter2;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'peerEurekaNodes'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Post-processingofmergedbeandefinitionfailed;nestedexceptionisjava.lang.IllegalStateException:FailedtointrospectClass[org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration$RefreshablePeerEurekaNodes]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]
atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...19commonframesomitted
Causedby:org.springframework.beans.factory.UnsatisfiedDependencyException:Errorcreatingbeanwithname'eurekaServerContext'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Unsatisfieddependencyexpressedthroughmethod'eurekaServerContext'parameter2;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'peerEurekaNodes'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Post-processingofmergedbeandefinitionfailed;nestedexceptionisjava.lang.IllegalStateException:FailedtointrospectClass[org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration$RefreshablePeerEurekaNodes]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]
atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...32commonframesomitted
Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'peerEurekaNodes'definedinclasspathresource[org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]:Post-processingofmergedbeandefinitionfailed;nestedexceptionisjava.lang.IllegalStateException:FailedtointrospectClass[org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration$RefreshablePeerEurekaNodes]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:558)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...46commonframesomitted
Causedby:java.lang.IllegalStateException:FailedtointrospectClass[org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration$RefreshablePeerEurekaNodes]fromClassLoader[sun.misc.Launcher$AppClassLoader@18b4aac2]
atorg.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659)~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:519)~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:207)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:188)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:127)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:297)~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1022)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...56commonframesomitted
Causedby:java.lang.NoClassDefFoundError:org/springframework/cloud/context/environment/EnvironmentChangeEvent
atjava.lang.Class.getDeclaredMethods0(NativeMethod)~[na:1.8.0_144]
atjava.lang.Class.privateGetDeclaredMethods(Class.java:2701)~[na:1.8.0_144]
atjava.lang.Class.getDeclaredMethods(Class.java:1975)~[na:1.8.0_144]
atorg.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641)~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
...63commonframesomitted
Causedby:java.lang.ClassNotFoundException:org.springframework.cloud.context.environment.EnvironmentChangeEvent
atjava.net.URLClassLoader.findClass(URLClassLoader.java:381)~[na:1.8.0_144]
atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)~[na:1.8.0_144]
atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)~[na:1.8.0_144]
atjava.lang.ClassLoader.loadClass(ClassLoader.java:357)~[na:1.8.0_144]
...67commonframesomitted
在确定了注解和properties配置文件都没有问题后,一开始以为是springBoot的版本和SpringCloud的版本冲突导致的
pom文件中,springBoot的版本是2.0.3
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/><!--lookupparentfromrepository-->
</parent>
springcloud的版本是Finchley.RELEASE,众所周知cloud的版本是以伦敦地铁站的英文名命名,Finchley对于的版本是2.0.X,具体的依赖如下所示:
分析:
查看了二者对应的版本,cloud是2.0.x以后的版本对应的boot也是2.0以后。因此不存在版本问题。后续查找了相关的资料,发现有人说,在cloud项目中,链路追踪是比不可少的环节,然后查看了一些自己Eureka-service的配置,发现在pom依赖中没有添加hystrix的依赖。所以添加了相关依赖:
再次启动后,不在报错。后来发现,在搭建cloud项目的时候,如果不配置hystrix,可能会出现各种异常,但是解决办法都是一样的,添加hystrix就好。
本文内容总结:
原文链接:https://www.cnblogs.com/gongchengshiwhl/p/12841046.html