728x90
반응형
1. Multi Profile
- 로컬, 테스트, 운영 서버 등 프로젝트를 진행하는 환경에 따라 여러 설정 값을 다르게 할 수 있다.
- Multi Profile을 사용하면 매번 환경 설정을 수정할 필요 없이 적용할 수 있다.
2. SpringBoot에서 Multi Profile 설정
- application.yml 파일에서 설정 가능
- --- 을 통해 프로필 구분
- 실제 환경을 나눠서 진행하지 않아서 DB 환경은 동일하게 하고 나눠서 설정만 해봤다.
- 실제로는 각 환경에 따라 DB 환경도 달라질 것이다.
- 만일 공통된 값을 모든 환경에 적용하기 위해서는 common 이라는 프로필을 만들어서 설정 가능하다.
- 제일 위에 공통된 값을 사용하고 싶은 환경에만 common 프로필을 추가해주면 된다.
- 현재 아래 코드는 spring.profiles.group에 환경에 따라 local, dev, stg, prod로 나눴다.
- spring.config.activate.on-profile을 통해 각 프로필마다 설정 가능
spring:
profiles:
group:
local: profile1
dev: profile2
stg: profile3
prod: profile4
---
spring:
config:
activate:
on-profile: profile1
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PW}
---
spring:
config:
activate:
on-profile: profile2
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PW}
---
spring:
config:
activate:
on-profile: profile3
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PW}
---
spring:
config:
activate:
on-profile: profile4
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PW}
728x90
반응형
'Web > Backend' 카테고리의 다른 글
[Backend] Swagger 설정 (1) | 2024.09.11 |
---|---|
[Backend] Logback 설정 (1) | 2024.09.11 |
[Spring] @Controller와 @RestController (0) | 2024.01.05 |
[SpringBoot] sts4 프로젝트 생성 (0) | 2024.01.04 |