Spring.io的Spring cloud配置示例无法正常工作

时间:2018-01-17 10:45:20

标签: java spring spring-boot spring-cloud spring-cloud-config

我正在尝试实施spring.io

中显示的示例

关于Spring Cloud集中配置,但是当涉及到启动服务器时,有一个奇怪的编译错误:

java.lang.NoClassDefFoundError: org/springframework/boot/actuate/health/AbstractHealthIndicator
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_141]
at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[na:1.8.0_141]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_141]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0_141]
at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_141]
at java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_141]
at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_141]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_141]
at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_141]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_141]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_141]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_141]
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_141]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_141]
at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_141]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:697) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:640) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1484) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:425) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at com.example.cloud.demoCloudConfig.DemoCloudConfigApplication.main(DemoCloudConfigApplication.java:12) [classes/:na]Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.health.AbstractHealthIndicator
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_141]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_141]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_141]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_141]
... 35 common frames omitted

pom.xml和@SpringBootClasses,application.properties与我提供的链接相同,所以请看这个链接:

https://spring.io/guides/gs/centralized-configuration/

它会出现什么问题?

2 个答案:

答案 0 :(得分:1)

请在ur maven中检查以下依赖关系

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

如果存在,请在eclipse中正确检查maven配置。 NoClassDefFoundError on Maven dependency

答案 1 :(得分:0)

库的版本存在问题。 考虑到即使是官方Spring教程也无法在我的计算机上运行,​​这实际上是一个不兼容(或与我的系统)或库之间的问题。

显然,春季示例中公开的版本1.5.9.RELEASE无法正常工作。

我已经尝试克隆该示例的github存储库获得相同的编译错误。

在这种特定情况下,切换到版本1.5.5.RELEASE解决了这个问题。