{Hostname}:{Port} 와 ServiceName을 전달하고ext {
set('springCloudVersion', "2023.0.1")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
server:
port: 8761
eureka:
client:
register-with-eureka: false //자기자신을 디스커버리 서버에 등록하지 않도록 false
fetch-registry: false //30초 마다 레지스트리 정보를 가져오는 옵션, 서버에서는 이미 가지고 있기에 false
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryserviceApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryserviceApplication.class, args);
}
}
@EnableEurekaServer 어노테이션을 사용하여 활성화 시켜준다. 기본 포트는 8761 번이다.
Eureka에 서비스를 등록하기 위해서는 서비스에서 EurekaClient 라이브러리를 사용하여 등록을 수행한다.
ext {
springCloudVersion = "2023.0.1"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
}
}
spring:
application:
name: secondServer
server:
port: 8082
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
Eureka Server와 다른 점은 spring.application.name에 이름을 명시해야 하는 것과
register-with-eureka, fetch-registry의 값을 true로 설정해야 한다.
그리고 service-url에 eureka 서버의 주소를 알려줘야 한다.
github 참고)
https://github.com/ajou20658/spring-cloud-toy/tree/master/eureka-server