在测试类上添加以下注释,测试时自动创建Spring的应用上下文:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:beans.xml" })或者@ContextConfiguration("classpath:beans.xml")
—————————————————————————————————————————————————————————
注意:@ContextConfiguration的value默认就是“locations",所以@ContextConfiguration的以上两种写法一样,如下:
@AliasFor("locations")
String[] value() default {};