Failed to load ApplicationContext (with annotation)

前端 未结 2 1788
闹比i
闹比i 2021-02-13 02:00

This is my class for test.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 02:26

    Your test requires a ServletContext: add @WebIntegrationTest

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
    @WebIntegrationTest
    public class UserServiceImplIT
    

    ...or look here for other options: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

    UPDATE In Spring Boot 1.4.x and above @WebIntegrationTest is no longer preferred. @SpringBootTest or @WebMvcTest

提交回复
热议问题