Spring Boot单元测试方法Failed to load ApplicationContext

 初步调试Spring Boot测试方法中, 启动出现了以下问题:

ction:

Consider defining a bean of type 'java.lang.Integer' in your configuration.

2020-07-07 15:57:57.808 ERROR 43332 --- [           main] o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@647fd8ce] to prepare test instance [com.zhaoyanhui.spring.boot.test.ZyhSpringBootTest@10ad20cb]

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ~[spring-test-5.1.2.RELEASE.jar:5.1.2.RELEASE]

解决办法如下:
在pom.xml中添加测试依赖:

 <!-- 支持单元测试:SpringBootTest -->
        <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>

 

 


版权声明:本文为xmldtd123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。