spring
여러 profile을 하나의 YAML으로 작성해 사용
nari0_0
2023. 9. 19. 18:13
728x90
이전글에 properties 와 yaml을 비교하는 글을 작성했는데 그중 yaml 파일에 여러개 profile 을 하나의 파일에 작성가능한 기능이 있어 이를 테스트 해보고 적용하려고 합니다.
.yml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: 4ones
url: jdbc:mysql://127.0.0.1:3306/test_db
password: qwerasdfzxcv
server:
name: a_server
port: '9090'
---
spring:
config:
activate:
on-profile: test
logging:
level:
org:
hibernate: debug
name: test-YAML
abc:
client: test-client
secret-key: qpwoei123qpwoeio
servers:
- www.test.abc.com
- www.test.xyz.com
---
spring:
config:
activate:
on-profile: prod
logging:
level:
org:
hibernate: info
name: prod-YAML
abc:
client: prod-client
secret-key: abcasdf123adf
servers:
- www.abc.com
- www.xyz.com
---
'---' 기호로 profile 구분합니다.
spring.config.activate.on-profile : profile 명
어플리케이션 로드시 profile을 정하는 방법:
1) .yml에서 spring.profiles.active: profile 입력
2) Intellij 툴에서 active profiles에 profile을 입력
3) 터미널 실행 java -jar ./app.jar -Dspring.profiles.active=test
728x90