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

前端 未结 4 2082
遥遥无期
遥遥无期 2020-12-01 04:22

I have the following test class:

@ActiveProfiles({ \"DataTC\", \"test\" })
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {BaseTestC         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 04:46

    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)

提交回复
热议问题