Not able to register a service as Eureka Client

14,193

Solution 1

The important thing is select the right import. I lost hours before realizing that:

This is the bare dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>

This is the starter pack dependency wanted in most case:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

If you import the bare dependency, no errors or logs will show up but the service will not register to Eureka server.

Bottom line, make sure to double double check the dependencies: maybe you need the "starter pack" dependency for a Spring boot component.

Solution 2

Problem solved, I didn't include dependency 'com.netflix.eureka:eureka-client:1.1.147' in my build.gradle.

Solution 3

Do the following in pom.xml

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<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>

In Spring boot configuration do the following:

@EnableDiscoveryClient @SpringBootApplication

public class ServiceApplication

Solution 4

service.application.properties
spring.application.name=rating-data-service
server.port=8083
eureka.client.eureka-server-port=8761 // on which port server is running
#eureka.client.register-with-eureka=false
#eureka.client.fetch-registry=false

server.application.properties

server.port=8761
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Share:
14,193
OD Street
Author by

OD Street

Updated on June 09, 2022

Comments

  • OD Street
    OD Street about 2 years

    I'm trying to register a Microservice as Eureka Client in order to discover other Microservices, however, I follow the tutorial but nothing shows up in the Eureka Server. Below are code snippets:

    1. My demo application: a spring boot application running on localhost:9001, I want it become a Eureka Client, i.e., register itself as an instance and meanwhile has ability to discover other instances (I used the generic @EnableDiscoveryClientannotation and Spring Netflix Eureka is on the classpath):

      @RestController
      @SpringBootApplication
      @EnableDiscoveryClient
      public class DemoApplication {
      
      @RequestMapping("/") 
      String home() {
          return "This is a Demo project";
      }
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);  
      }
      }
      
    2. application.yml:

      server:
        port: 9001
      
      eureka:
        client:
          serviceUrl:
              defaultZone: http://localhost:8761/eureka/
      

    The Eureka Server should be no problem since I have another Miscroservice running on localhost:8080 is successfully registered in the server. Just in case here is the application.yml for the Eureka Server:

    server:
      port: 8761
    
    eureka:
      instance:
        hostname: localhost
      client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
    

    Anyone see any problems here?

  • Abhiram mishra
    Abhiram mishra about 6 years
    You should use the spring cloud dependency rather adding netflix directly
  • Mr.Q
    Mr.Q over 4 years
    @EnableDiscoveryClient is not needed in Spring Cloud Finchley and later