spring boot properties working with multi-document files, activation properties
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config.files
properties를 여러개 나눠놓고 환경별 지정하는 것은 익히 사용하던 방법인데, 최근에 알게된 내용을 정리한다.
multi module로 나뉘어진 프로젝트에서 application.properties를 template처럼 하나 만들어 놓고, active profile 마다 주입되서 동작할 수 있도록 가능하다는 것이다.
/web <– 실제 운영하기 위한 module
-> application-local.yml
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/membership username: root password: root web -> build.gradle.kts
dependencies { implementation(project(":mysql")) ... }
/mysql <– datasource 관련 module
-> application.yml
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: ${spring.datasource.url} username: ${spring.datasource.username} password: ${spring.datasource.root} jpa: hibernate: ddl-auto: validate show-sql: true
이런 형태로 구성할 경우 profile에 맞춰서 mysql의 application.yml의 properties에 변수들이 주입되어 관리할 수 있다.
환경 변수별로 여러개를 작성하지 않아도 관리가 편리하게 할 수 있다는 것을 알게되어 남겨놓는다.
This article is licensed under CC BY 4.0 by the author.