Following the instructions here, but i get the error unable to autowire WebApplicationContext.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("applicationContext-test.xml")
@WebAppConfiguration
public class AjaxTest {
@Autowired
private WebApplicationContext webApplicationContext; //FAILS
But this compiles :
@Autowired
ServletContext servletContext;
private WebApplicationContext webApplicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
And I don’t understand why.
Edit
It runs fine using maven, it was my editor intellij showing an incorrect auto compile message, a bug in fact.
Your test class should implement
ApplicationContextAwareinterface:Spring will automatically inject the application context.