Spring-batch metadata tables in different schema

前端 未结 2 1534
慢半拍i
慢半拍i 2021-01-02 11:39

I have a datasource that connects to an Oracle database in my application. Is it possible to access to another schema that includes the Spring-batch metadata tables through

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 12:09

    Because spring.batch.table-prefix=.batch_ did not work for me and I could not immediately configure the second datasource, I took a look at the actual table generation done by Spring Batch.

    The sql-Script which generates the tables is static (at least in the release 4.2.2 and for Postgresql). Therefore it is no wonder that spring.batch.table-prefix does not work. At least in my case as the tables do not yet exist in the database.

    To fix it I copied schema-postgresql.sql to my resource folder and modified it to my needs (creating the schema and referencing it explicitly).

    CREATE SCHEMA SPRING_BATCH;
    
    CREATE TABLE SPRING_BATCH.BATCH_JOB_INSTANCE  (
        JOB_INSTANCE_ID BIGINT  NOT NULL PRIMARY KEY ,
        -- and so on 
    

    In my application.properties I added:

    spring.batch.initialize-schema=always
    spring.batch.table-prefix=SPRING_BATCH.BATCH_
    spring.batch.schema=classpath:db/create_spring_batch_tables.sql
    

提交回复
热议问题