Not able to register a service as Eureka Client
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
OD Street
Updated on June 09, 2022Comments
-
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:
My
demo
application: a spring boot application running onlocalhost: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@EnableDiscoveryClient
annotation 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); } }
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 about 6 yearsYou should use the spring cloud dependency rather adding netflix directly
-
Mr.Q over 4 years@EnableDiscoveryClient is not needed in Spring Cloud Finchley and later