尽管注册了Bean,但Scala单元测试无法自动接线的Spring

时间:2019-06-14 13:23:03

标签: java spring scala junit

我有一个资源服务,我正在尝试在此测试类中自动布线。它在应用程序xml中注册,并带有运行器和所有其他好东西。安装完全相同的Java版本不会失败。

@RunWith(classOf[SpringJUnit4ClassRunner])
@ContextConfiguration(Array("classpath*:/applicationContext.xml"))
class RequestSuite extends JUnitSuite
  with TableDrivenPropertyChecks with Matchers with BeforeAndAfterAll {

  ...

  var myServiceResource = new MyServiceResource

  @Autowired
  var beanFactory: AutowireCapableBeanFactory = null

  beanFactory.autowireBean(myServiceResource)
  ...
}

另一方面,上面的代码在我调用beanFactory时会抛出一个空指针,因为它从未被初始化。

0 个答案:

没有答案