You cannot use autwire spring beans for static. You should do this with an instance method instead, and let it assign the value to a variable static(which will work just fine):
@Autowired
public void setApplicationContext(ApplicationContext applicationContext) {
AuditorTest.applicationContext = applicationContext;
}
But I do not think that this is what you want. I think you should annotate the test class with SpringJUnitRunnerand @ContextConfiguration, and then you can autwire ApplicationContextthere:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(...)
public class TestClass {
@Autowired
private ApplicationContext context;
}
source
share