初步调试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>