postgresql Spring 批次/发布日期:错误:关系“批处理作业示例”不存在

bweufnob  于 2023-02-04  发布在  PostgreSQL
关注(0)|答案(5)|浏览(111)

我正在尝试配置Spring Batch以使用PostGres DB。我在build.gradle.kts文件中包含了以下依赖项:

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

我的SpringBatch模块的application.yml包含以下内容:

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容器的日志中看到以下错误:
Spring批次:

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

后灰色:

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,但没有变化。

6psbrbz9

6psbrbz91#

请检查以下添加到应用程序.yml

spring.batch.initialize-schema: always

请检查是否添加了以下依赖项

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

sczxawaw2#

yaml文件是

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=1234
spring.datasource.driver-class-name=org.postgresql.Driver
spring.batch.jdbc.initialize-schema=always

等级依赖关系

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-batch'
    implementation 'org.projectlombok:lombok-maven-plugin:1.18.6.0'
    implementation group: 'org.postgresql', name: 'postgresql', version: '42.3.1'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.batch:spring-batch-test'
}
xtfmy6hx

xtfmy6hx3#

您需要设置spring.batch.initialize-schema=always属性以告知Sping Boot 自动创建Spring批处理表。有关详细信息,请参阅Spring Boot参考文档的初始化Spring批处理数据库部分。

aemubtdh

aemubtdh4#

对于已经设置了spring.batch.initialize-schema=always但仍然无法正常工作的用户,还要验证您连接到数据库的用户是否具有足够的权限,包括创建必要表的权限。

8yoxcaq7

8yoxcaq75#

在www.example.com中application.properties,
我们可以使用之前的Sping Boot 2.5

spring.batch.initialize-schema=ALWAYS

更新版本的Sping Boot 2.5使用如下

spring.batch.jdbc.initialize-schema=ALWAYS

相关问题