場景:學習spring實戰中相關的單元測試spring
@ContextConfiguration Spring整合JUnit4測試時,使用註解引入多個配置文件app
@ContextConfiguration(locations="../applicationContext.xml")單元測試
@ContextConfiguration(classes = SimpleConfiguration.class)學習
可用{}測試
@ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" })spa
能夠根據測試的類名,去找到與之對應的配置文件。code
異常狀況:xml
異常信息blog
四月 12, 2017 9:38:10 上午 org.springframework.test.context.support.AbstractContextLoader generateDefaultLocations 信息: Could not detect default resource locations for test class [soundsystem.CNamespaceValueTest]: class path resource [soundsystem/CNamespaceValueTest-context.xml] does not exist 四月 12, 2017 9:38:10 上午 org.springframework.test.context.support.AnnotationConfigContextLoaderUtils detectDefaultConfigurationClasses 信息: Could not detect default configuration classes for test class [soundsystem.CNamespaceValueTest]: CNamespaceValueTest does not declare any static, non-private, non-final, inner classes annotated with @Configuration.
1it