SSM项目中,关于Test类中不能使用Autowired注入bean的问题

在测试类中使用AutoWired注解一直不能获取到Bean,调用方法时一直报空指针异常,我有在其他类中使用AutoWired试了下,发现能够生效。问题应该就是处在Test类中,后面找了半天终于找到问题了!!!

解决方法:

 测试类上加如下注解:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")

猜你喜欢

转载自www.cnblogs.com/weiqang/p/11316270.html
今日推荐