-
[Spring] springBoot2.4 이상에서의 application설정스프링 2023. 12. 29. 02:15
1. spring.profiles.active
default로 사용될 프로파일을 명시하는 기능
- 해당 값을 명시하지 않는 경우 default 프로파일(application.yml)이 사용됨
2. spring.config.activate.on-profile
- 해당 프로파일이 선택되었을 때만 활성화
- 프로파일 활성화시 사용할 속성을 정의할 수 있다.
- dev, prod, local, test 등으로 나눠서 사용 가능
- 반대로 spring.config.activate.on-profile 프로퍼티가 없는 영역은 활성화된 프로파일과 무관하게 모든 프로파일들에서 공통적으로 사용된다.
3. spring.profiles.group.{group-name}
- 그룹에 작성한 프로파일을 활성화할 수 있다.
ex) spring.profiles.group.dev: db-dev
4. 주의사항
YAML 파일 마지막에 spring.config.activate.on-profile선언할 것
- 마지막에 선언한 것으로 덮어쓴다.
5. test에서 사용할 때
- @ActiveProfiles()에 사용할 프로파일을 정의할 수 있다.
// test에 사용할 yaml 파일 적용 @ActiveProfiles("test") @SpringBootTest @AutoConfigureMockMvc class UserControllerTest { // ... }
728x90'스프링' 카테고리의 다른 글
성능 개선을 진행해보자 1편 (0) 2024.07.03 빈 등록과 주입을 아라보자 (1) 2024.05.15 [Spring] Error - Parameter 0 of constructor in ~ required a bean of type 'java.lang....' that could not be found. (0) 2023.12.29 [JUnit5] @ParameterizedTest, @ValueSource, @CsvSource (0) 2023.11.01 Service계층의 의존 (0) 2023.08.30