Next, we are going to reuse the Spring Boot-based temperature service that we created in Chapter 1, From Monoliths to Microservices.
First, we'll define the Maven dependencies for Eureka as shown here:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
Then, we'll add the @EnableEurekaClient annotation to our application configuration:
@EnableEurekaClient
@SpringBootApplication
public class EurekaWeatherService {
public static void main(String... args) {
SpringApplication.run(EurekaWeatherService.class);
}
}
To make our temperature service aware of the Eureka Server, we are going to add some configurations, defined in a .YML file, as follows:
spring:
application:
name: spring-cloud-eureka-client
server:
port: 0
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
instance:
preferIpAddress: true
After invoking the main method on the EurekaWeatherService class and then requesting http://localhost:8761, you should see that our application is registered with the server: