You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Batch连接PostgreSQL时提示'relation "batch_job_instance" does not exist'但表实际已存在的问题求助

Spring Batch连接PostgreSQL时提示'relation "batch_job_instance" does not exist'但表实际已存在的问题求助

大家好,我现在遇到一个Spring Batch连接PostgreSQL的问题,想请各位帮忙排查下:

我正在基于Spring Boot 2.7.2开发Spring Batch项目,数据库使用的是PostgreSQL。

当我执行命令 mvn spring-boot:run 启动应用时,遇到了如下错误:

org.postgresql.util.PSQLException: ERROR: relation "batch_job_instance" does not exist Position: 39

但实际上batch_job_instance表已经存在于我的数据库中——我通过执行SELECT * FROM batch_job_instance;验证过,这个查询能正常返回数据,没有任何报错。

我已经尝试了以下几种排查手段:

  • 确认应用连接的数据库正确性:执行SELECT current_database();,返回的是我预期的数据库名称,连接没问题。
  • 验证表在系统表中的存在性:执行SELECT * FROM pg_tables WHERE tablename = 'batch_job_instance';,能查到对应结果,再次确认表确实存在。
  • 配置层面:已经设置spring.batch.initialize-schema=never,因为表是提前创建好的,不需要框架自动初始化。
  • 显式指定schema查询:执行SELECT * FROM public.batch_job_instance;,这个查询也能正常运行。

我的application.properties配置如下:

spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=myuser
spring.datasource.password=mypassword
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL10Dialect
spring.batch.initialize-schema=never
spring.jpa.hibernate.ddl-auto=none

现在我有几个疑问:

  1. 为什么明明表存在,Spring Batch却找不到batch_job_instance表呢?
  2. 会不会是schema的问题?我该怎么显式配置让Spring Batch去正确的schema里查找表?
  3. PostgreSQL和Spring Batch配合使用,还有哪些需要额外注意的配置吗?

希望有经验的朋友能帮我解决这个问题,非常感谢!

备注:内容来源于stack exchange,提问作者T.S. E-A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:33:07