지금까지 각 프로젝트에 application.yml을 만들었음
한곳에서 관리하도록 변경할 예정
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
server:
port: 8888
spring:
application:
name: config-service
profiles:
active: native # 로컬 파일 가져오겠다고 명시
cloud:
config:
server:
native:
search-locations: file://${user.home}/Desktop/spring-config/git-local-repo
git:
uri: https://github.com/LEEJAECHEOL/spring-cloud-config
# private 일 경우
#username:
#password:
# uri: file:///Users/lee/Desktop/spring-config/git-local-repo
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
spring:
cloud:
config:
uri: http://127.0.0.1:8888
name: ecommerce
profiles:
active: dev
# 서버 정보가 바뀔때 마다 다시 가져오는 3가지 방법
# 서버 재기동
# Actuator refresh -> Spring Boot Actuator 사용
# Spring cloud bus 사용
server:
port: 8000
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://localhost:8761/eureka
spring:
application:
name: apigateway-service
cloud:
gateway:
default-filters:
- name: GlobalFilter
args: # Global Filter 내 inner Class의 Config class 에 값이 들어감.
baseMessage: Spring Cloud Gateway Global Filter
preLogger: true
postLogger: true
routes:
# - id: user-service
# uri: lb://USER-SERVICE
# predicates:
# - Path=/user-service/**
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/login # 로그인
- Method=POST
filters:
- RemoveRequestHeader=Cookie # 전달되는 데이터를 매번 새롭게 인식하기 위해서 삭제
- RewritePath=/user-service/(?<segment>.*), /$\{segment} # /user-service/login -> /login 으로 변경
- id: user-service
uri: lb://USER-SERVICE
predicates:
- Path=/user-service/users # 회원가입
- Method=POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
- id: user-service
uri: lb://USER-SERVICE
predicates: # 조건절
- Path=/user-service/**
- Method=GET
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
- AuthorizationHeaderFilter
- id: user-service
uri: lb://USER-SERVICE
predicates: # 조건절
- Path=/user-service/actuator/**
- Method=GET,POST
filters:
- RemoveRequestHeader=Cookie
- RewritePath=/user-service/(?<segment>.*), /$\{segment}
- id: catalog-service
uri: lb://CATALOG-SERVICE
predicates:
- Path=/catalog-service/**
- id: order-service
uri: lb://ORDER-SERVICE
predicates:
- Path=/order-service/**
- id: first-service
uri: lb://MY_FIRST-SERVICE
predicates:
- Path=/first-service/**
filters:
# - AddRequestHeader=first-request, first-request-header2
# - AddResponseHeader=first-response, first-response-header2
- name: CustomFilter
- name: LoggingFilter # 만약에 args를 넣어야한다면 filters 내에 name: 을 앞에 추가해서 구분해줘야함.
args:
baseMessage: Hi, there
preLogger: true
postLogger: true
- id: second-service
uri: lb://MY-SECOND-SERVICE
predicates:
- Path=/second-service/**
filters:
# - AddRequestHeader=second-request, second-request-header2
# - AddResponseHeader=second-response, second-response-header2
- CustomFilter
management:
endpoints:
web:
exposure:
include: refresh, health, beans, httptrace
#token:
# secret: user_token
management:
endpoints:
web:
exposure:
include: refresh, health, beans