Dev./java
[Spring Cloud Netflix] Eureka Server, Client 설정
인쥭
2021. 7. 17. 20:20
반응형
- Spring Boot 2.5.2
- IntelliJ 2020.3.3
1. Eureka Server
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
server:
port: 8761
eureka:
instance:
appname: injuk-server
client:
fetch-registry: false
register-with-eureka: true
@SpringBootApplication
@EnableEurekaServer
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
2. Eureka Client
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
server:
port: 8080
eureka:
instance:
appname: injuk-client
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka/
@SpringBootApplication
@EnableEurekaClient
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
3. Eureka dashboard 접속
- http://localhost:8761
- http://localhost:8761/eureka/apps도 확인해보자.
배운 것
- 포트 겹치면 당연히 안됨
- EnableEurekaClient와 EnableDiscoveryClient는 다름 (참고)
- dependencies에 eureka client용과 server용을 같이 넣지 말자.
- 에러가 발생하며 실행되지 않는다. 실습해본다고 spring initializr에서 다 체크해서 문제가 발생하였음...
- error getting CloudEurekaClient
- Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource, 등
- > 이유 찾아보기
- 에러가 발생하며 실행되지 않는다. 실습해본다고 spring initializr에서 다 체크해서 문제가 발생하였음...