일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Eclipse
- IntelliJ
- STS
- oracle
- MSSQL
- Python
- MySQL
- Exception
- error
- Source
- 설정
- Thymeleaf
- JavaScript
- 문서
- git
- AJAX
- PostgreSQL
- 오픈소스
- Docker
- Tomcat
- Open Source
- Core Java
- Spring Boot
- JDBC
- maven
- myBatis
- SpringBoot
- spring
- jpa
- ubuntu
- Today
- Total
헤르메스 LIFE
[Spring Cloud Netflix] Eureka Gateway 샘플 본문
아래와 같은 환경을 구축하기 위해 Microservice 가 1개 이상 있어야 합니다.
Spring Cloud 아키텍처 관계도
개발환경
JDK : Zulu JDK 17.0.10
SpringBoot 3.2.3
SpringBoot Eureka Client ( 현재 최신 버전 :4.1.0 )
Build Tools : Gradle
1. 프로젝트 생성
2. Eureka Gateway
- 간단한 Application 입니다.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'octopus'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2023.0.0")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
// Default :: 1.18.30
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()
}
application.yml
server:
port: 8080
eureka:
client:
fetch-registry: false
register-with-eureka: false
service-url:
#defaultZone: http://localhost:8761/eureka/ # Eureka Server 경로
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/} # http://localhost:8761/eureka/ 와 같은 설정임.
spring:
application:
name: Eureka-Gateway
cloud:
gateway:
routes:
- id: service01
uri: http://localhost:8081
predicates:
- Path=/service01/** # "Path" 반드시 첫글자 대문자
- id: service02
uri: http://localhost:8082
predicates:
- Path=/service02/** # "Path" 반드시 첫글자 대문자
FilterConfig.java
package octopus.config;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FilterConfig {
@Bean
public RouteLocator gatewayRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/service01/**")
.filters(f -> f.addRequestHeader("first-request", "first-request-header")
.addResponseHeader("first-response", "first-response-header"))
.uri("http://localhost:8081"))
.route(r -> r.path("/service02/**")
.filters(f -> f.addRequestHeader("first-request", "second-request-header")
.addResponseHeader("first-response", "second-response-header"))
.uri("http://localhost:8082"))
.build();
}
}
3. Eureka Gateway를 통한 Uri 호출
http://localhost:8080/service01/welcome
- http://localhost:8081/service01/welcome 를 Gateway를 통해서 http://localhost:8080/service01/welcome 를 접속해도 같은 Uri로 이동할 수 있게 됩니다.
http://localhost:8080/service02/welcome
- http://localhost:8081/service01/welcome 를 Gateway를 통해서 http://localhost:8080/service01/welcome 를 접속해도 같은 Uri로 이동할 수 있게 됩니다.
https://hermeslog.tistory.com/755
[Spring Cloud Netflix] Eureka Server 개발
https://github.com/hermeswing/EureakServer GitHub - hermeswing/EureakServer: Spring Eureka Server Spring Eureka Server. Contribute to hermeswing/EureakServer development by creating an account on GitHub. github.com 개발환경 JDK : Zulu JDK 17.0.10 Sprin
hermeslog.tistory.com
https://hermeslog.tistory.com/760
[Spring Cloud Netflix] Eureka Service 개발
아래와 같은 환경을 구축하기 위해 Microservice 가 1개 이상 있어야 합니다. Spring Cloud 아키텍처 관계도 출처 : https://spring.io/cloud 개발환경 JDK : Zulu JDK 17.0.10 SpringBoot 3.2.3 SpringBoot Eureka Client ( 현재 최
hermeslog.tistory.com
https://hermeslog.tistory.com/762
[Exception] java.lang.IllegalArgumentException: Unable to find RoutePredicateFactory with name path
개발환경 JDK : Zulu JDK 17.0.10 SpringBoot 3.2.3 SpringBoot Eureka Client ( 현재 최신 버전 :4.1.0 ) Build Tools : Gradle 다음과 같은 오류가 발생하였습니다. java.lang.IllegalArgumentException: Unable to find RoutePredicateFactory wi
hermeslog.tistory.com
'Spring Boot Framework' 카테고리의 다른 글
[Springboot] Springboot 와 Mybatis 설정에서 resultType을 Map 으로 사용 시 문제점. (0) | 2024.07.24 |
---|---|
[Spring Boot] Mybatis 쿼리 Interceptor 처리 테스트 (0) | 2024.05.23 |
[Spring Cloud Netflix] Eureka Client 샘플 (0) | 2024.03.14 |
[Spring Cloud Netflix] Eureka Server 샘플 (2) | 2024.03.10 |
[P6Spy] p6spy 설정 시 두 번 찍히는 경우 (0) | 2024.02.01 |