hoony's web study

728x90
반응형

오늘은 예전부터 생성하고 싶었던 Eureka Server를 만들어 보았습니다.

전자정부프레임워크에서 소개한 pom.xml 로는 계속 에러가 나서 gradle로 변경해서 적용을 해보았습니다. 

Build.gradle 작성

plugins {
    id 'org.springframework.boot' version '2.7.3'
    id 'io.spring.dependency-management' version '1.0.13.RELEASE'
    id 'java'
}

group = 'kr.ourcodelabs'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "2021.0.3")
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

gradle로 하니 정말 편하게 돌아갑니다. 

application.yml 설정

server:
  port: 8761
spring:
  application:
    name: EurekaServer
eureka:
  instance:
    hostname: localhost
    preferIpAddress: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

서버포트는 8761로 설정을 했구요. 
registerWithEureka : false 는 화면에서 Eureka server는 안 보이도록 설정을 하는 것입니다. 

Java Source

package kr.ourcodelabs.jspmaneurekaserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

//EurekaServer 를 사용하기 위해 Annotation 을 추가해준다.
@SpringBootApplication
@EnableEurekaServer
public class JspManEurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(JspManEurekaServerApplication.class, args);
    }

}

적용화면

정말 간단하게 연동되어있는 서버의 상태를 확인하실 수 있습니다. 
더 많은 옵션은 있으나 현재 제가 필요한 것은 jar의 instance가 떠 있는지 확인하는 용도라서 여기까지만 적용을 해보았습니다. 

그럼 Client 는 다음 포스팅에 남기도록 하겠습니다.

 

728x90

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading