一般对于有bean注入的类进行方法单元测试时,会发现bean对象并没有注入进来,对象是null。这种情况可以使用如下方式解决:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/META-INF/spring/applicationContext.xml" })
public class AOPTest extends AbstractJUnit4SpringContextTests{
@AutoWired
private AService aService;
@Test
public void test(){
//TODO
}
}