ApplicationContext의 기능들을 살펴보자
Environment environment = ctx.getEnvironment();
System.out.println(Arrays.toString(environment.getActiveProfiles()))
// []
System.out.println(Arrays.toString(environment.getDefaultProfiles()))
// [default]
@Configuration
@Profile("test")
public class TestConfiguration {
@Bean
public BookRepository bookRepository() {
return new TestBookRepository();
}
}
@Autowired
BookRepository bookRepository; // test 프로파일이 아니면 불가능
-Dspring.profiles.active = 'test,A,B'
@Repository
@Profile("test")
public class TestBookRepository implements BookRepository {}
아래와 같은 설정도 가능
@Profile("!prod")
not 사용 가능@Profile("test & prod")