java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling

One of your @Configuration classes is obviously annotated with @EnableWebMvc. That’s how DelegatingWebMvcConfiguration ends up in your stack trace, since it is imported by @EnableWebMvc.

So although you think you don’t need a WebApplicationContext (and hence a ServletContext), you in fact do need it simply because you are loading an application context with @EnableWebMvc.

You have two options:

  • Compose the configuration classes for your integration test so that you are not including the web-related configuration (i.e., the @Configuration class(es) annotated with @EnableWebMvc).
  • Annotate your test class with @WebAppConfiguration as suggested in other comments above.

Regards,

Sam (author of the Spring TestContext Framework)

Leave a Comment