(转)@ContextConfiguration注解说明


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

1 正常使用

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

1.1 单个文件

@ContextConfiguration(locations="../applicationContext.xml")

@ContextConfiguration(classes = SimpleConfiguration.class)

1.2 多个文件

可用{}

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

1.3 默认不写

可以根据测试的类名,去找到与之对应的配置文件。

 异常情况:

异常信息

四月 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.

 

 

1

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM