问题
I'm using Spring Cloud Eureka and creating the project using Spring Initializr (http://start.spring.io/). The generated POM user Eureka Finchley.RC2 with Spring Boot 2.0.2.RELEASE. When I add the annotation @EnableEurekaServer
in the main class, the one annotated with @SpringBootApplication
also, and I start the server with following command:
mvn spring-boot:run
I receive the exception
java.lang.ClassNotFoundException: com.netflix.discovery.EurekaClientConfig
the following is the pom.xml generated by the Initializr:
<?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>it.javaboss</groupId>
<artifactId>api-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>api-gateway</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RC2</spring-cloud.version>
</properties>
<dependencies>
<!-- <dependency> -->
<!-- <groupId>org.springframework.cloud</groupId> -->
<!-- <artifactId>spring-cloud-starter-config</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
回答1:
I found the eureka-clien-1.9.2.jar in my local maven repository is ZERO length file, so I deleted it and re-download the dependency, all is ok!
回答2:
hope to help someone - i had same issue java.lang.NoClassDefFoundError:com/netflix/discovery/converters/XmlXStream when launch eureka server, version i used springboot 2.0.3.RELEASE and spring-cloud.version Finchley.RELEASE. i resolved it by rename my local maven repo user-folder.m2\repository, fresh load a new local maven repo.
回答3:
Try to use below dependencies in your pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</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>
<finalName>eureka-server</finalName>
</build>
回答4:
As 'rosa lu' said, when launch eureka server I have the similar issue as below:
java.lang.NoClassDefFoundError:com/netflix/discovery/converters/XmlXStreamSpringBoot=2.0.5.RELEASE
SpringCloud.version=Finchley.SR1
As 'rosa lu' said, I change my local maven repository to a new path, and rebuild my project, then solve the problem
I hope my answer can help anyone who has the same issue .
回答5:
Make sure that
- You should select only Eureka Server using spring Initializr while creating eureka server project.
Have these properties (in application.properties)
eureka.client.register-with-eureka=false eureka.client.fetch-registry=false
These will disable the client aspect the the eureka server.
- You might be having
com.netflix.discovery.EurekaClientConfig
imported somewhere in your project. So organize your imports once.
回答6:
I finally solved the propblem in two different solution:
1.adding two more dependencies:
<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.5</version>
</dependency>
2.renaming application.yml in bootstrap.yml and disabling autoregistration:
eureka:
client:
registerWithEureka: false
fetchRegistry: false
but in this second way I still need to add the dependency to jettison:
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.3.5</version>
</dependency>
来源:https://stackoverflow.com/questions/50675895/java-lang-classnotfoundexception-com-netflix-discovery-eurekaclientconfig