Spring batch 运行弹簧批量测试,不';不能初始化数据库

Spring batch 运行弹簧批量测试,不';不能初始化数据库,spring-batch,integration-testing,Spring Batch,Integration Testing,尝试为spring批处理应用程序创建一些端到端测试,效果非常好。我收到一个sql错误,因为它没有初始化Spring批处理表:org.postgresql.util.psqleexception:error:relation“Batch\u job\u instance”不存在 我在src/test/resources/application.properties中有这段代码: spring.datasource.initialize=true spring.datasource.initiali

尝试为spring批处理应用程序创建一些端到端测试,效果非常好。我收到一个sql错误,因为它没有初始化Spring批处理表:
org.postgresql.util.psqleexception:error:relation“Batch\u job\u instance”不存在

我在
src/test/resources/application.properties
中有这段代码:

spring.datasource.initialize=true
spring.datasource.initialization-mode=always
spring.datasource.platform=postgresql

spring.batch.initialize-schema=always
这与我在`src/main/resources/application.properties和works上看到的相同

这是我为
ApplicationTest
编写的代码:

@RunWith(SpringRunner.class)
@上下文配置(类)={
TestConfiguration.class,
JobCompletionNotificationListener.class,
BatchConfiguration.class
})
@弹簧批试验
公共类应用程序测试{
@自动连线
私有JobLauncherTestUtils JobLauncherTestUtils;
@试验
public void testJob()引发异常{
JobExecution JobExecution=JobLaunchTestUtils.launchJob();
}
}
我有一个特定的
TestConfiguration
来使用
DataSource
生成
Bean

@配置
@PropertySource(“application.properties”)
公共类测试配置{
@自动连线
私人环境署;
@豆子
公共数据源数据源(){
DriverManager数据源dataSource=新的DriverManager数据源();
setDriverClassName(env.getProperty(“spring.dataSource.driverClassname”);
setUrl(env.getProperty(“spring.dataSource.url”);
setUsername(env.getProperty(“spring.dataSource.username”);
setPassword(env.getProperty(“spring.dataSource.password”);
返回数据源;
}
我希望创建所有表(内部批处理表和在
schema all.sql
中定义的表)

但是我得到以下错误
org.postgresql.util.psqleexception:error:relation“batch\u job\u instance”不存在


我不明白为什么主应用程序中的所有程序都是自动工作的,而在测试中却没有。

您是否尝试在测试中添加数据源?我刚刚尝试过,但我得到了相同的错误。因为您自己在
TestConfiguration
中创建了数据源,所以它不会自动填充。我将删除此数据源bean定义,然后让Spring Boot在测试中完成它(就像在生产代码中一样)删除
TestConfiguration
后,我得到以下错误:
没有可用的类型为“javax.sql.DataSource”的符合条件的bean
。我添加了
TestConfiguration
,因为在测试期间Spring没有创建步骤中所需的
@Autowired
数据源
。我不知道是否丢失了g导致此
数据源
无法创建的内容。