봄 부팅 테스트 방법의 ApplicationContext를로드하지 못했습니다

오늘, 봄 부트 시험 방법, 다음과 같은 문제의 갑작스러운 외관 :

java.lang.IllegalStateException는 :의 ApplicationContext를로드하지 못했습니다
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext (DefaultCacheAwareContextLoaderDelegate.java:124)에서
org.springframework.test.context.support.DefaultTestContext.getApplicationContext에서 (DefaultTestContext.java : 83)
...

다음과 같은 해결 방법은 다음과 같습니다
추가 시험의 pom.xml에 의존

<!-- SpringBootText注解依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

<!-- Junit依赖 -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>

시험 종류 :

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class SearchTest {

    @Autowired
    private AccountDao mapper;
    
    @Test
    public void test2() {
        Account a = new Account();
        a.setName("李四");
        a.setPassword("123");
        a.setLevel(1);
        mapper.save(a);
    }
}

참고 시작 클래스 App.java 와 컨트롤러, 서비스, DAO 클래스 계층 구조!

위의 문제를 해결 할 수있을 것입니다 테스트 클래스에 @SpringBootTest 및 @RunWith 코멘트를 추가

추천

출처www.cnblogs.com/dagger9527/p/11836722.html