SpringBeanAutowiringSupport does not inject beans in jUnit tests

后端 未结 2 1654
醉酒成梦
醉酒成梦 2021-01-07 12:32

I use SpringBeanAutowiringSupport for bean injection in some objects. Problem is, that injection of beans does not work in jUnit tests. For testing is used SpringJUnit4Class

2条回答
  •  甜味超标
    2021-01-07 12:49

    well spring + junit team have already fixed this . look this link -- >
    spring unit testing

    otherwise you can call the spring context and use the getBean method , but in that way you can even do it with a simple main test inside your class instead of junit test

    **note if you use the spring + junit config you have to put the test-spring-context.xml into the test package

提交回复
热议问题