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 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 @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?
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.
Problem solved, I didn't include dependency 'com.netflix.eureka:eureka-client:1.1.147' in my build.gradle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With