2016-09-08 91 views
2

我正在使用Spring-Boot與Spring-Batch,我有我的application.properties中的數據源配置,但我不希望春天批處理創建表我的數據庫,所以我用下面的配置Spring引導(spring批處理)配置禁用數據庫的自動創建

@Configuration 
@EnableBatchProcessing 
public class BatchConfiguration { 

@Autowired 
public JobBuilderFactory jobBuilderFactory; 

@Autowired 
public StepBuilderFactory stepBuilderFactory; 

@Bean 
public Job myJob() { 
    return jobBuilderFactory.get("myJob").incrementer(new RunIdIncrementer()) 
      .listener(listener()).flow(step2()).end().build(); 
} 

@Bean 
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(final JobRegistry jobRegistry) { 
    JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor(); 
    jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry); 
    return jobRegistryBeanPostProcessor; 
} 

@Bean 
public Step step2() { 
    LOGGER.info("step2"); 
    return stepBuilderFactory.get("step2").tasklet(new PurchaseStatusBatch()).build(); 
} 

@Bean 
public JobOperator jobOperator() throws Exception { 
    SimpleJobOperator jobOperator = new SimpleJobOperator(); 
    jobOperator.setJobExplorer(jobExplorer()); 
    jobOperator.setJobLauncher(jobLauncher()); 
    jobOperator.setJobRegistry(jobRegistry()); 
    jobOperator.setJobRepository(getJobRepo()); 
    return jobOperator; 
} 

@Bean 
public JobRegistry jobRegistry() { 
    return new MapJobRegistry(); 
} 

@Bean 
public JobExplorer jobExplorer() throws Exception { 

    MapJobExplorerFactoryBean factoryExplorer = new MapJobExplorerFactoryBean(
      new MapJobRepositoryFactoryBean(getTransactionManager())); 
    factoryExplorer.afterPropertiesSet(); 
    return factoryExplorer.getObject(); 
} 

@Bean 
public JobLauncher jobLauncher() throws Exception { 
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); 
    jobLauncher.setJobRepository(getJobRepo()); 
    jobLauncher.afterPropertiesSet(); 
    return jobLauncher; 
} 

@Bean 
public PlatformTransactionManager getTransactionManager() { 
    return new ResourcelessTransactionManager(); 
} 

@Bean 
public JobRepository getJobRepo() throws Exception { 
    return new MapJobRepositoryFactoryBean(getTransactionManager()).getObject(); 
} 
} 

我用spring.batch.initializer.enabled=false禁用自動創建數據庫表

的在應用程序第一次運行,一切正常,但是當我嘗試lanch我的工作我得到MySQLSyntaxErrorException:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表只是因爲你已經禁用了自動生成的表 「BATCH_JOB_INSTANCE」不存在

回答

相關問題