Loading...
Spring Framework Reference Documentation 7.0.2의 Context Configuration with XML resources의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
XML 설정 file을 사용하여 test를 위한 ApplicationContext를 로드하려면,
test class에 @ContextConfiguration을 어노테이션으로 지정하고 locations attribute를
XML 설정 메타데이터의 리소스 location을 포함하는 array로 설정해야 합니다. 일반
또는 relative path(예: context.xml)는 test class가 정의된 패키지를 기준으로 하는
classpath 리소스로 처리됩니다.
슬래시로 시작하는 path는 절대 classpath location(예:
/org/example/config.xml)으로 처리됩니다. 리소스 URL을 나타내는 path(즉,
classpath:, file:, http: 등으로 prefix된 path)는 있는 그대로 사용됩니다.
1@ExtendWith(SpringExtension.class) 2// ApplicationContext will be loaded from "/app-config.xml" and 3// "/test-config.xml" in the root of the classpath 4@ContextConfiguration(locations = {"/app-config.xml", "/test-config.xml"}) // (1) 5class MyTest { 6 // class body... 7}
| 1 | locations attribute를 XML file list로 설정합니다. |
1@ExtendWith(SpringExtension::class) 2// ApplicationContext will be loaded from "/app-config.xml" and 3// "/test-config.xml" in the root of the classpath 4@ContextConfiguration(locations = ["/app-config.xml", "/test-config.xml"]) // (1) 5class MyTest { 6 // class body... 7}
| 1 | locations attribute를 XML file list로 설정합니다. |
@ContextConfiguration은 표준 Java value attribute를 통해 locations attribute에 대한
alias를 지원합니다. 따라서 @ContextConfiguration에서 추가 attribute를 선언할 필요가
없다면, locations attribute 이름 선언을 생략하고 다음 예제에 나와 있는 shorthand
format을 사용하여 리소스 location을 선언할 수 있습니다:
1@ExtendWith(SpringExtension.class) 2@ContextConfiguration({"/app-config.xml", "/test-config.xml"}) // (1) 3class MyTest { 4 // class body... 5}
| 1 | locations attribute를 사용하지 않고 XML file을 지정합니다. |
1@ExtendWith(SpringExtension::class) 2@ContextConfiguration("/app-config.xml", "/test-config.xml") // (1) 3class MyTest { 4 // class body... 5}
| 1 | locations attribute를 사용하지 않고 XML file을 지정합니다. |
@ContextConfiguration 어노테이션에서 locations와 value attribute를 둘 다 생략하면,
TestContext 프레임워크는 기본 XML 리소스 location을 감지하려고 시도합니다. 구체적으로,
GenericXmlContextLoader와 GenericXmlWebContextLoader는 test class 이름을 기반으로
기본 location을 감지합니다. class 이름이 com.example.MyTest인 경우,
GenericXmlContextLoader는 "classpath:com/example/MyTest-context.xml"에서
애플리케이션 컨텍스트를 로드합니다.
다음 예제는 이를 수행하는 방법을 보여 줍니다:
1@ExtendWith(SpringExtension.class) 2// ApplicationContext will be loaded from 3// "classpath:com/example/MyTest-context.xml" 4@ContextConfiguration // (1) 5class MyTest { 6 // class body... 7}
| 1 | 기본 location에서 설정을 로드합니다. |
1@ExtendWith(SpringExtension::class) 2// ApplicationContext will be loaded from 3// "classpath:com/example/MyTest-context.xml" 4@ContextConfiguration // (1) 5class MyTest { 6 // class body... 7}
| 1 | 기본 location에서 설정을 로드합니다. |
Context Management
Context Configuration with Groovy Scripts