ApplicationContext의 기능들을 살펴보자

Environment

프로파일

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 프로파일이 아니면 불가능

프로파일 설정 방법

컴포넌트에 바로 프로파일 정의하는 방법

@Repository
@Profile("test")
public class TestBookRepository implements BookRepository {}

아래와 같은 설정도 가능