class MyWebAppInitializer extends WebApplicationInitializer {
def onStartup(servletContext: ServletContext): Unit = {
...
}
}
@RunWith(classOf[SpringJUnit
In your context configuration I don't see that you have a context loader listed. The AnnotationConfigWebContextLoader will locate instances of WebApplicationInitializer on your classpath, by adding this and removing the intializers (which, as you have noted, are for ApplicationContextInitializers and not WebApplicationInitializers) then you should be all set.
@RunWith(classOf[SpringJUnit4ClassRunner])
@WebAppConfiguration
@ContextConfiguration(classes = {ConfigClass.class, AnotherConfigClass.class}, loader=AnnotationConfigWebContextLoader.class))
class MyTest {
...
Here is a working example
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes={WebConfiguration.class, SecurityConfig.class}, loader=AnnotationConfigWebContextLoader.class)
@ActiveProfiles("dev")
public class AppTests {
private MockMvc mockMvc;
@Autowired
protected WebApplicationContext webApplicationContext;
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void simple() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.view().name("index"));
}
}