标签:XML auto tco AC int classes red bean import
package cn.itcast.d_junit4; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import cn.itcast.c_all_annotation.SpringConfiguration; import cn.itcast.domain.User; //在测试代码执行前创建spring容器 @RunWith(SpringJUnit4ClassRunner.class) //指定配置文件位置 //读取xml配置 @ContextConfiguration("classpath:applicationContext.xml") //读取类配置 //@ContextConfiguration(classes=SpringConfiguration.class) public class Demo { @Autowired private User user; @Test public void fun1(){ System.out.println(user); } }
如果不用@RunWith(SpringJUnit4ClassRunner.class)进行整合,则@Test无法执行applicationContext容器中存储的对象
标签:XML auto tco AC int classes red bean import
原文地址:https://www.cnblogs.com/qingyundian/p/9079366.html