Profiles와 Environment
Spring profiles(@Profile), application-{profile}.properties, profile 활성화, 환경 변수
1Spring에서 @Profile 어노테이션은 무엇을 할 수 있게 해주나요?
Spring에서 @Profile 어노테이션은 무엇을 할 수 있게 해주나요?
답변
@Profile 어노테이션은 활성화된 profile에 따라 bean이나 설정의 활성화를 조건부로 제어할 수 있게 해줍니다. profile이 활성화되면(spring.profiles.active를 통해) 해당 profile로 어노테이션된 bean만 Spring 컨텍스트에 로드됩니다. 이를 통해 코드를 중복하지 않고도 dev, test, production에 서로 다른 설정을 둘 수 있습니다. 예를 들어 dev에서는 H2 데이터베이스를, production에서는 PostgreSQL을 사용할 수 있습니다.
2애플리케이션 시작 시 Spring Boot profile을 활성화하는 속성은 무엇인가요?
애플리케이션 시작 시 Spring Boot profile을 활성화하는 속성은 무엇인가요?
답변
spring.profiles.active 속성은 시작 시 하나 이상의 profile을 활성화합니다. application.yml, 커맨드 라인(--spring.profiles.active=prod), 또는 환경 변수로 정의할 수 있습니다. 이 속성은 실행 환경(dev, test, prod)을 선택하는 표준 방법입니다.
3'production' profile 전용 설정 파일의 이름은 어떻게 지정하나요?
'production' profile 전용 설정 파일의 이름은 어떻게 지정하나요?
답변
profile별 설정 파일은 application-{profile}.yml 또는 application-{profile}.properties 패턴을 따릅니다. 'production' profile의 경우 파일명은 application-production.yml이 됩니다. 이러한 파일은 해당 profile이 활성화될 때 메인 application.yml의 속성을 오버라이드합니다.
spring.profiles.active와 spring.profiles.include의 차이점은 무엇인가요?
Spring의 Environment 인터페이스란 무엇인가요?
+17 면접 질문