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

前端 未结 5 1296
逝去的感伤
逝去的感伤 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:15

    If anyone uses Spring boot and don't want to remove @EntityScan and @EnableJpaRepositories you can remove @WebMvcTest annotation from your test class and add the following instead:

    @RunWith(SpringRunner.class)
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    @AutoConfigureMockMvc
    public class DemoControllerIntegrationTests {
        @Autowired
        private MockMvc mvc;
    
        //...
    }
    

    and you will be able to autowire MockMvc and use it.

提交回复
热议问题