(转)@ContextConfiguration注解说明

场景:学习spring实战中相关的单元测试spring

1 正常使用

@ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件app

1.1 单个文件

@ContextConfiguration(locations="../applicationContext.xml")单元测试

@ContextConfiguration(classes = SimpleConfiguration.class)学习

1.2 多个文件

可用{}测试

@ContextConfiguration(locations = { "classpath*:/spring1.xml", "classpath*:/spring2.xml" })spa

1.3 默认不写

能够根据测试的类名,去找到与之对应的配置文件。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

相关文章
相关标签/搜索