测试类需要添加@ContextConfiguration注解
源java中不需要添加是因为配置了应用上下文
- eg:
**@ContextConfiguration : 加载配置文件
@ContextConfiguration(classes = {TestConfig.class})//适用于加载配置类
@ContextConfiguration用来加载ApplicationContext
classes属性用来加载配置类
比如:
1. 单个文件
@ContextConfiguration(Locations="…/applicationContext.xml")//加载配置文件
@ContextConfiguration(classes = SimpleConfiguration.class)
2. 多个文件时
@ContextConfiguration(locations = { “classpath*:/springapplication1.xml”, “classpath*:/springapplication2.xml” })**