일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 시큐리티 로그아웃
- 시큐리티 로그인
- codingtest
- 로그인
- css
- springboot
- 시큐리티로그인
- 반복문
- Spring boot
- sql
- StyleSheet
- JAVA11
- 리눅스
- html
- 싱글톤
- 코딩테스트
- security
- 소스트리
- 목록
- input태그
- java
- 스프링 부트
- programmers
- 프로그래머스
- 시큐리티
- javascript
- springSecurity
- 2차원배열
- Linux
- gradle
Archives
- Today
- Total
JAVAIARY
EUREKA Server Local 구축 및 서비스 추가 본문
원래는 AWS에 올라가 있는 서버에 서비스를 추가하려고 했으나,
그게 맘처럼 잘 안돼서 (...) 로컬로 해 보기로 했다.
1. Eureka서버 로컬에서 구축하기
Eureka_local 이름으로 프로젝트를 하나 생성하고 build.gradle 수정
plugins {
id 'java'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'org.example'
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server")
implementation 'com.google.code.gson:gson:2.10'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2021.0.5"
}
}
test {
useJUnitPlatform()
}
- Eureka-server Dependency를 추가해 준다.
그리고 application.yml에서 유레카 서버 관련 설정을 해준다.
spring:
application:
name: eureka_server
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
- eureka-client-defaultZone의 URL 로 유레카 서버가 생성이 된다.
- registerWithEureka : 서버 본인은 인스턴스에 등록할 필요가 없기 때문에 false로 둔다.
- fetchRegistry : 상동
main 아래에 패키지를 하나 만들고 어플리케이션을 작성한다.
package com.server.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class);
}
}
- @EnableEurekaServer 어노테이션을 작성해 해당 어플리케이션이 Eureka Server임을 명시해준다.
어플리케이션 실행 후 http://localhost:8761로 접속하면
유레카 서버를 확인할 수 있다 👍
2. Eureka에 서비스 추가하기
1) 서비스할 프로젝트의 build.gradle
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
eureka-client dependency 추가
2) application.yml
spring:
application:
name: kiosk_test
profiles:
active: TEST_KIOSK_API
---
spring:
profiles: TEST_KIOSK_API
cloud:
discovery:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
register-with-eureka: true
fetch-registry: true
instance:
prefer-ip-address: true
server:
port: 9685
- spring-application-name : 유레카에 추가 될 인스턴스명이 됨
- 유레카 정보 추가
3) Application에 어노테이션 추가
@EnableDiscoveryClient
그리고 어플리케이션 실행을 해 준다.
지정한 포트로 인스턴스가 올라와 있는 것을 확인할 수 있다.
'lectureNote > SPRING' 카테고리의 다른 글
Bean, Container (0) | 2023.12.17 |
---|---|
Spring Security - 10. 번외 1 로그아웃 (0) | 2023.01.02 |
Spring Security - 9. 기존 프로젝트에 적용하기 (0) | 2022.12.25 |
Spring Security - 8. 자동로그인!! (0) | 2022.12.21 |
Spring Security - 7. 표현식과 동적 화면 구성 (0) | 2022.12.21 |