春ブーツ試験方法の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