soft IT life
spring on-profile 기능 사용(서버프로필에 따라 properties 세팅 변화) 본문
서버의 profile에 따라 configuration, properties 세팅을 다르게 설정해주고 싶다면?
ex) object storage 같은 서비스를 이용할 때에는 버킷을 여러개 두고 사용이 가능하다.
따라서 test용 버킷과 실 production 버킷을 따로 두고 사용할 수 있다. but How??
같은 서버 하나로 test용/ production용... 등으로 나누어 사용하고싶다면...?
서버의 profile을 다르게 설정해주어 properties 데이터를 각 profile에 맞게 세팅해줄 수 있다. 어디서? application.yml
아래 코드를 보면,
서버의 프로필이 dev일 때 -> bucket이 test용으로 세팅
서버의 프로필이 prod일 때 -> bucket이 실버킷으로 세팅 되는 것이다..
object-storage:
accessKey:
secretKey:
bucket: magicbucketlocal
endpoint: https://kr.object.ncloudstorage.com
region: kr-standard
spring:
datasource:
url: jdbc:mysql://175.45.200.193:3306/
driverClassName: com.mysql.cj.jdbc.Driver
username: e
password:
logging:
level:
Exposed: debug
---
spring:
config:
activate:
on-profile: dev
object-storage:
bucket: magicbuckettest
---
spring:
config:
activate:
on-profile: prod
object-storage:
bucket: magicbucket
서버의 profile 지정 하는 법?
intellij IDEA 사용 환경 =>
참고: application.properties 와 application.yml파일이 동일한 패키지에 위치하면 yml 파일이 우선적으로 읽힌다.
'Kotlin' 카테고리의 다른 글
Validation spring+kotlin, DTO/Entity/Repository (0) | 2023.09.14 |
---|---|
2023.09.08 금 - Insight (0) | 2023.09.08 |
Kotlin 기초 2 - 조건식, 반복문, nullable, class, 생성자 (0) | 2023.09.05 |
kotlin 기초 1 - 함수, 변수 (0) | 2023.08.30 |