我未在配置的架构中创建Spring Batch元数据表

时间:2019-07-02 09:48:44

标签: java spring spring-batch

我正在为我的批处理作业配置一个具有现有数据源和LocalContainerEntityManagerManagerFactoryBean的JpaTransactionManager。调试时,JpaTransactionManager设置为“ dbs”模式,我希望元数据表应该放在该模式下。但实际上,元数据表是在“公共”模式下创建的。我正在使用的数据库是'postgress'

我尝试扩展DefaultBatchConfigurer以及所有可能的方法,结果仍然相同

这是我的application.yml文件:

spring:
  datasource:
    url: ${DB_URL:jdbc:postgresql://127.0.0.1:5432/postgres}
    username: ${DB_USER_NAME:postgres}
    password: ${DB_PASSWORD:******}
    driver-class-name: org.postgresql.Driver
  jpa:
    show-sql: false
    properties:
      hibernate:
        format_sql: false
        generate_statistics: true
        dialect: org.hibernate.dialect.PostgreSQLDialect
        default_schema: dbs
    hibernate:
      ddl-auto: none
  batch:
    job:
      enabled: false
    initializer:
      enabled: true

批处理配置文件如下:

public class StatusBatchConfig extends DefaultBatchConfigurer {

    @Autowired
    private DataSource dataSource;

    @Override
    @Bean
    @Primary
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTransactionManager(transactionManager());
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    @Primary
    public JpaTransactionManager transactionManager() {
        JpaTransactionManager transactionManager = new JpaTransactionManager();
        transactionManager.setDataSource(dataSource);
        transactionManager.setEntityManagerFactory(entityManagerFactory.getObject());
        String schema = (String) entityManagerFactory.getObject().getProperties().get("hibernate.default_schema");
        System.out.println(schema); //prints 'dbs'
        return transactionManager;
    }



    @Bean
    public SimpleJobLauncher jobLauncher(JobRepository jobRepository) {
        SimpleJobLauncher launcher = new SimpleJobLauncher();
        try {
            launcher.setJobRepository(createJobRepository());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return launcher;
    }

}

在此处还需要配置什么以将元数据表保存为“ dbs”模式

0 个答案:

没有答案