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

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

I have the following test class:

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


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 05:05

    It seems like you are missing

    @WebAppConfiguration
    

    from your test class.

    The documentation states

    The resource base path is used behind the scenes to create a MockServletContext which serves as the ServletContext for the test’s WebApplicationContext.

    Typically a Servlet container would provide the ServletContext. Since you are in a testing environment, you need a fake. @WebAppConfiguration provides that.

提交回复
热议问题