Loading...
Spring Framework Reference Documentation 7.0.2의 @ContextConfiguration의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
@ContextConfiguration@ContextConfiguration은 integration test를 위한 ApplicationContext를 어떻게 로드하고 구성할지 결정하는 데 사용되는 메타데이터를 구성하기 위해 test 클래스에 적용할 수 있는 어노테이션입니다. 구체적으로, @ContextConfiguration은 컨텍스트를 로드하는 데 사용되는 애플리케이션 컨텍스트 리소스 locations 또는 컴포넌트 classes를 선언합니다.
리소스 location은 일반적으로 classpath에 위치한 XML 설정 파일 또는 Groovy 스크립트인 반면, 컴포넌트 클래스는 일반적으로 @Configuration 클래스입니다. 그러나 리소스 location은 파일 시스템의 파일 및 스크립트를 가리킬 수도 있고, 컴포넌트 클래스는 @Component 클래스, @Service 클래스 등일 수도 있습니다. 자세한 내용은
Component Classes를 참조하십시오.
다음 예제는 XML 파일을 참조하는 @ContextConfiguration 어노테이션을 보여 줍니다:
1@ContextConfiguration("/test-config.xml") // (1) 2class XmlApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | XML 파일을 참조합니다. |
1@ContextConfiguration("/test-config.xml") // (1) 2class XmlApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | XML 파일을 참조합니다. |
다음 예제는 클래스를 참조하는 @ContextConfiguration 어노테이션을 보여 줍니다:
1@ContextConfiguration(classes = TestConfig.class) // (1) 2class ConfigClassApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | 클래스를 참조합니다. |
1@ContextConfiguration(classes = [TestConfig::class]) // (1) 2class ConfigClassApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | 클래스를 참조합니다. |
리소스 location 또는 컴포넌트 클래스를 선언하는 대신 또는 그에 더해, @ContextConfiguration을 사용하여 ApplicationContextInitializer 클래스를 선언할 수 있습니다. 다음 예제는 이러한 경우를 보여 줍니다:
1@ContextConfiguration(initializers = CustomContextInitializer.class) // (1) 2class ContextInitializerTests { 3 // class body... 4} 5// Copied!
| 1 | 이니셜라이저 클래스를 선언합니다. |
1@ContextConfiguration(initializers = [CustomContextInitializer::class]) // (1) 2class ContextInitializerTests { 3 // class body... 4} 5// Copied!
| 1 | 이니셜라이저 클래스를 선언합니다. |
선택적으로 @ContextConfiguration을 사용하여 ContextLoader 전략도 선언할 수 있습니다. 그러나 일반적으로 로더를 명시적으로 구성할 필요는 없습니다. 기본 로더가 initializers와 리소스 locations 또는 컴포넌트 classes 중 하나를 지원하기 때문입니다.
다음 예제는 location과 로더를 모두 사용합니다:
1@ContextConfiguration(locations = "/test-context.xml", loader = CustomContextLoader.class) // (1) 2class CustomLoaderXmlApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | location과 custom 로더를 모두 구성합니다. |
1@ContextConfiguration("/test-context.xml", loader = CustomContextLoader::class) // (1) 2class CustomLoaderXmlApplicationContextTests { 3 // class body... 4} 5// Copied!
| 1 | location과 custom 로더를 모두 구성합니다. |
| 참고 | @ContextConfiguration은 superclass나 enclosing 클래스에 의해 선언된 리소스 location 또는 설정 클래스뿐만 아니라 컨텍스트 이니셜라이저를 상속하는 기능을 제공합니다. |
자세한 내용은 Context Management,
@Nested test 클래스 설정,
그리고 @ContextConfiguration
javadoc을 참조하십시오.
@BootstrapWith
@WebAppConfiguration