我是新的Spring批處理引導。我在使用postgres作爲數據庫配置jobRepositoryFactory bean時遇到了問題。 下面是我的配置類。Spring批處理與Spring引導 - 配置JobRepositoryFactoryBean
@Configuration
@EnableBatchProcessing
@Import(DataSourceConfiguration.class)
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
private PlatformTransactionManager transactionManager;
private final DataSourceConfiguration dataSourceConfiguration;
public BatchConfiguration(DataSourceConfiguration dataSourceConfiguration) {
this.dataSourceConfiguration = dataSourceConfiguration;
}
@Bean
public ElasticReader elasticReader() {
return new ElasticReader();
}
@Bean
public JobRepository jobRepositoryFactoryBean() throws Exception {
JobRepositoryFactoryBean fb = new JobRepositoryFactoryBean();
fb.setDatabaseType("postgres");
fb.setDataSource(dataSourceConfiguration.dataSource());
fb.setTransactionManager(transactionManager);
return fb.getObject();
}
@Bean
public PlatformTransactionManager platformTransactionManager() {
return transactionManager;
}
@Bean
public StageReader stageReader(){
return new StageReader();
}
@Bean
public DocumentItemProcessor processor() {
return new DocumentItemProcessor();
}
@Bean
public ExcelWiter writer() {
return new ExcelWiter();
}
@Bean
public StageWriter stageWriter() {
return new StageWriter();
}
@Bean
public Job importUserJob() {
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.flow(step1())
.next(step2())
.end()
.build();
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<List<JsonObject>,List<JsonObject>> chunk(10)
.reader(stageReader())
.writer(stageWriter())
.build();
}
@Bean
public Step step2() {
return stepBuilderFactory.get("step2")
.<List<OnboardConfigVO>,List<ExportVO>> chunk(10)
.reader(elasticReader())
.processor(processor())
.writer(writer())
.build();
}
}
DataSourceConfiguration.class
@PropertySource("classpath:/batch-postgresql.properties")
public class DataSourceConfiguration {
@Autowired
private Environment environment;
@Autowired
private ResourceLoader resourceLoader;
@PostConstruct
protected void initialize() {
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(resourceLoader.getResource(environment.getProperty("bach.schema.script")));
populator.setContinueOnError(true);
DatabasePopulatorUtils.execute(populator , dataSource());
}
@Bean(destroyMethod="close")
public DataSource dataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName
(environment.getProperty(batch.jdbc.driver");
dataSource.setUrl(environment.getProperty("batch.jdbc.url"));
dataSource.setUsername(environment.getProperty("batch.jdbc.user"));
dataSource.setPassword(environment.getProperty("batch.jdbc.password"));
return dataSource;
}
這裏是春天的輸出啓動應用程序運行
Using default security password: f5cddd58-4790-427c-83b8-b6c25044db7f
2017-08-09 09:36:59.589 INFO 42576 --- [ main]
o.s.s.web.DefaultSecurityFilterChain : Creating filter chain:
OrRequestMatcher [requestMatchers=[Ant [pattern='/css/**'], Ant
[pattern='/js/**'], Ant [pattern='/images/**'], Ant
[pattern='/webjars/**'], Ant [pattern='/**/favicon.ico'], Ant
[pattern='/error']]], []
2017-08-09 09:36:59.785 INFO 42576 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9199 (http)
2017-08-09 09:36:59.790 INFO 42576 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2017-08-09 09:36:59.794 INFO 42576 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta
data indicating: POSTGRES
2017-08-09 09:36:59.798 INFO 42576 --- [ main]
o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set,
defaulting to synchronous executor.
我在配置類配置的豆類。我在這裏錯過了什麼?
問題是什麼?它連接到您的Postgresql數據庫... –
@MichaelMinella 問題(我認爲)是INFO警告* 2017-08-09 09:36:59.794 INFO 42576 --- [main] osbcrsJobRepositoryFactoryBean:沒有數據庫類型集,使用meta 的數據指示:POSTGRES * – lakshmanvvs
So?您沒有在您的配置中指定實際的數據庫類型,因此metdata會正確地指出它。這實際上只是一個信息消息。它可以被忽略。 –