My linux world » Java Spring – MicroServices

Java Spring - MicroServices


Contents

Prerequistes

Please read : Java spring – quickstart

Configuration

If you use maven, add this to your pom.xml

<dependencies>
(...)
 
  !-- Spring Cloud starter -->
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter</artifactId>
  </dependency>
 
  <!-- Eureka for service registration -->
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka-server</artifactId>
  </dependency>
 
(...)
</dependencies>

Server Part

Enable eureka server :

@EnableEurekaServer
@EnableDiscoveryClient
public class EurekaServerConfiguration {
  // empty.
}

Client Part

Enable eureka client :

@EnableEurekaClient
@EnableDiscoveryClient
public class EurekaClientConfiguration {
  // empty.
}

application.yml

Create the file src/main/resources/application.yml :

eureka:
  instance:
    leaseRenewalIntervalInSeconds: 10
  client:
    registryFetchIntervalSeconds: 5
    serviceUrl:
      defaultZone: http://${server.hostname}:${server.port}/eureka/
 
spring.application.name: myservice

boostrap.yml

Create the file src/main/resources/boostrap.yml :

spring:
  cloud:
    config:
      enabled: false

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.