Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

postgresql - Spring Batch / Postgres : ERROR: relation "batch_job_instance" does not exist

I am trying to configure Spring Batch to use PostGres DB. I have included the following dependencies in my build.gradle.kts file:

implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.postgresql:postgresql")

My application.yml for my SpringBatch module has the following included:

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

However, when I try to add a data file I see the following error in the logs of both my SpringBatch Docker container, and the PostGres container:

Spring Batch:

<<< 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

I can see that the SB server is picking up POSTGRES from my metadata ok.

JobRepositoryFactoryBean     : No database type set, using meta data indicating: POSTGRES

What am I missing to get the initial db configured during the server start?

Edit: I've tried adding spring.datasource.initialize=true explicitly, but no change.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please check below added in application.yml

spring.batch.initialize-schema: always

Please check below dependencies are added

<artifactId>spring-boot-starter-batch</artifactId>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...