Junit单元测试注入spring中的bean(转载)

转载自:http://blog.csdn.net/cy104204/article/details/51076678

 

一般对于有bean注入的类进行方法单元测试时,会发现bean对象并没有注入进来,对象是null。这种情况可以使用如下方式解决:

 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/spring/applicationContext.xml" })
public class AOPTest extends AbstractJUnit4SpringContextTests{

   @AutoWired
   private AService aService;

   @Test
   public void test(){
     //TODO 
   }
}

posted @ 2017-03-14 17:49  大象踢足球  阅读(5455)  评论(0编辑  收藏  举报