看起来新的 Spring Cloud 版本的 Netflix 有一些问题。我正在尝试在本地运行 eureka 服务器并尝试注册它,我看到以下异常。我认为 Spring Boot 会拉取所有 dpendency。
这里是例外:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.Bootstrapper : org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapper
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:475)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:457)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:450)
at org.springframework.boot.SpringApplication.getBootstrapRegistryInitializersFromSpringFactories(SpringApplication.java:294)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:285)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:266)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
at org.example.MyApp.main(MyApp.java:10)
Caused by: java.lang.NoClassDefFoundError: com/netflix/discovery/shared/resolver/EurekaEndpoint
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3305)
at java.base/java.lang.Class.getConstructor0(Class.java:3510)
at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2691)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:470)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.netflix.discovery.shared.resolver.EurekaEndpoint
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 13 more
我的应用程序.yml
server:
port: 8081
spring:
application:
name: MyApp
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8677/eureka/
我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SimpleBootApp</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.5.6</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- Thanks for using https://jar-download.com -->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
我没有发现任何人报告此问题,请帮忙
您需要添加依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
我知道这是一个老问题,但我最近遇到了同样的问题。当在 Spring 环境中手动/以编程方式实例化 Eureka 客户端时,Spring Cloud 启动者不一定会添加您需要的所有内容,而无需准确复制他们正在执行的操作(从 Spring 角度来看,这本身就是一个非标准用例)。
无论如何,失踪的班级是Archaius的一部分。就我而言,添加 archaius-core 依赖项解决了这个问题:
<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId>
<version>0.7.12</version>
</dependency>