Getting “At least one JPA metamodel must be present” with @WebMvcTest

前端 未结 5 1295
逝去的感伤
逝去的感伤 2021-02-05 06:02

I\'m fairly new to Spring, trying to do some basic integration tests for a @Controller.

@RunWith(SpringRunner.class)
@WebMvcTest(DemoController.clas         


        
5条回答
  •  终归单人心
    2021-02-05 06:18

    Add @MockBean(JpaMetamodelMappingContext.class) to above of class DemoControllerIntegrationTests:

    @RunWith(SpringRunner.class)
    @WebMvcTest(DemoController.class)
    @MockBean(JpaMetamodelMappingContext.class)
    public class DemoControllerIntegrationTests {
        ...
    }
    

    Because you have not used a database in your test, Spring throws this exception. By mocking JpaMetamodelMappingContext class you will bypass the needed metamodel.

提交回复
热议问题