【发布时间】:2021-08-25 22:58:50
【问题描述】:
所以我在尝试为模式和数据加载 .sql 脚本时遇到问题。
默认情况下我的脚本没有被加载,因为当我的测试尝试从 H2 db 获取数据时,显示消息“表”未找到”。
脚本位于“src/test/resources”文件夹中。 pom中的H2依赖:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
当我添加注释“@Sql(scripts = { "/schema.sql", "/data.sql" }) 时,我看到下一个错误:
java.lang.IllegalStateException:无法执行 SQL 脚本 测试上下文 [DefaultTestContext@7090eaec testClass = 微服务控制器测试,测试实例 = sche.invm.backend.rke.asn2019.get.controller.MicroserviceControllerTest@180274b1, testMethod = testGetPerson@MicroserviceControllerTest, testException = [空],合并上下文配置 = [WebMergedContextConfiguration@5158e446 testClass = MicroserviceControllerTest,位置 = '{}',类 = '{class sche.invm.backend.rke.asn2019.get.GetApplication}', contextInitializerClasses = '[]',activeProfiles = '{test}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=0}', contextCustomizers = 设置[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@30bbcf91, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@52b959df, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@31834a2b, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@34c53688, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@6127a7e], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', 父 = [null]],属性 = 地图['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> false]]: 无法从事务管理器 [org.springframework.orm.jpa.JpaTransactionManager] 获取数据源(命名为 '')。
¿ 可能是什么错误? 我的应用配置了多租户,我不知道这是否会导致此特定错误。
【问题讨论】:
标签: java integration-testing h2 spring-boot-test