Failed to load ApplicationContext (with annotation)

前端 未结 2 1789
闹比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:22

    In my case, I had to do the following while running with Junit5

    @SpringBootTest(classes = {abc.class}) @ExtendWith(SpringExtension.class

    Here abc.class was the class that was being tested

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题