首页  >  问答  >  正文

Spring批处理作业未在开发环境中启动

我使用 spring spring-boot-starter-batch 2.7.9 并以 mysql DB 作为数据源。我有一个奇怪的问题,批处理作业在我的本地运行,但无法在开发环境(kubernetes)中启动,异常如下:

Exception while starting job
    org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT into BATCH_JOB_EXECUTION_PARAMS(JOB_EXECUTION_ID, KEY_NAME, TYPE_CD, STRING_VAL, DATE_VAL, LONG_VAL, DOUBLE_VAL, IDENTIFYING) values (?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [HY000]; error code [3098]; The table does not comply with the requirements by an external plugin.; nested exception is java.sql.SQLException: The table does not comply with the requirements by an external plugin.

作业通过休息端 API 触发,该 API 提供两个作业参数:字符串和日期时间。

示例参数:

{
    "idType" : "ALL",
    "triggerTime": "2023-03-16T19:54:18.262Z" 
}

我的本​​地数据库和开发数据库之间的一个区别可能是复制因子。开发数据库配置了 3 个副本,而在本地我只有一个。这可能是这个异常的原因吗?我该如何解决这个问题? TIA。

P粉517814372P粉517814372410 天前540

全部回复(1)我来回复

  • P粉166675898

    P粉1666758982023-09-07 00:26:00

    您需要自定义 Spring Batch 元表的定义,以便每个表都有一个主键。

    默认情况下,MySQL 接受没有主键的表。但在任何使用 MySQL 复制的设置中,没有主键的表要么根本不起作用(如您的组复制情况),要么会导致日后的操作难题。

    根本原因是 Spring Batch 架构的 DDL 包含的索引数量非常有限。这是故意的,因为索引的最佳方法在很大程度上取决于特定的用例: https://docs.spring.io/spring-batch/docs/4.3.8/reference/html/schema-appendix.html#recommendationsForIndexingMetaDataTables

    回复
    0
  • 取消回复