我正在Spring Boot测试中尝试使用p6spy。我有一个带有注释的测试课
@RunWith(SpringRunner.class)
@SpringBootTest
我的gradle.build看起来像这样
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
runtime('com.h2database:h2')
testCompile 'p6spy:p6spy:3.0.0'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
至于应用程序本身(运行良好),我将新的数据源添加到了test-application-context中。
spring:
application:
name: persistence
datasource:
url: jdbc:p6spy:h2:mem:persistence;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
jpa:
database: H2
但是当我运行测试时出现此错误
java.lang.IllegalStateException: Cannot load driver class: com.p6spy.engine.spy.P6SpyDriver
对我来说,这似乎没有加载我的依赖项。最初,我使用的是@DataJpaTest批注,但此批注甚至忽略了我的新test-application-context。
任何帮助表示赞赏。
编辑:我可以通过使用IntelliJ将p6spy依赖项手动添加到测试中来工作。现在,我确定我的类路径是错误的,但是我不知道如何修复它以使其在Gradle中工作。
最佳答案
问题位于我的IntelliJ版本中。我将提交错误报告。
如果有人应该遇到此问题,我会在项目设置中手动添加缺少的依赖项。然后它也可以在IDE中工作。
关于java - 在Spring Boot测试中未加载Gradle测试依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46653435/