Spring MockMvc WebApplicationContext is null when running JUnit Tests with Maven
Spring MockMvc WebApplicationContext is null when running JUnit Tests with Maven I have a Spring mock-mvc JUnit test class that contains two tests. When I run the tests within Eclipse IDE both tests pass (I use Eclipse Maven plugin). When running the tests from the command line using mvn test one of the tests fails because the WebApplicationContext that is @Autowired is sometimes null. Here is my test class @WebAppConfiguration @ActiveProfiles({ "dev", "test" }) public class AddLinkEndpointMvcTest extends BaseMvc { @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void before() { System.out.println("WAC = " + wac); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } @Test public void addLinkDoesNotSupportGet() throws Exception { mockMvc.perform(get("/myurl")).andExpect(status().is(HttpStatus.SC_METHOD_NOT_ALLOWED)); } @Test public v...