SpringBatch/Postgres:错误:关系“batch_job_instance”不存在
我正在尝试配置 Spring Batch 以使用 PostGres DB。我在我的build.gradle.kts文件中包含了以下依赖项:
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.postgresql:postgresql")
我application.yml的 SpringBatch 模块包含以下内容:
spring:
datasource:
url: jdbc:postgresql://postgres:5432/springbatchdb
username: postgres
password: root
driverClassName: org.postgresql.Driver
docker-compose.yml
postgres:
restart: always
image: postgres:12-alpine
container_name: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=root
- POSTGRES_DB=springbatchdb
ports:
- "5432:5432"
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
但是,当我尝试添加数据文件时,我在 SpringBatch Docker 容器和 PostGres 容器的日志中看到以下错误:
春季批次:
<<< Exception in method: org.meanwhileinhell.spring.batch.server.SpringBatchController.handle Error Message: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is org.postgresql.util.PSQLException: ERROR: relation "batch_job_instance" does not exist
PostGres:
LOG: database system is ready to accept connections
2021-01-08 09:54:56.778 UTC [56] ERROR: relation "batch_job_instance" does not exist at character 39
2021-01-08 09:54:56.778 UTC [56] STATEMENT: SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = $1 and JOB_KEY = $2
2021-01-08 09:55:27.033 UTC [56] ERROR: relation "batch_job_instance" does not exist at character 39
2021-01-08 09:55:27.033 UTC [56] STATEMENT: SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = $1 and JOB_KEY = $2
我可以看到 SB 服务器正在从我的元数据中获取 POSTGRES 确定。
JobRepositoryFactoryBean : No database type set, using meta data indicating: POSTGRES
在服务器启动期间我缺少什么来配置初始数据库?
编辑:我试过spring.datasource.initialize=true明确添加,但没有改变。
回答
请检查以下添加在 application.yml 中
spring.batch.initialize-schema: always
请检查以下依赖项是否已添加
<artifactId>spring-boot-starter-batch</artifactId>
THE END
二维码