长期以来,我一直在努力解决这个问题,有人遇到过这种问题吗? 我需要根据特定条件致电作家,所以我尝试使用分类器,但是我的分类器没有被调用,并且所有的书写器都没有被调用。我正在使用Spring Batch 3
我长期以来一直在努力解决这个问题,有人遇到过这种问题吗?
@Configuration
public class JobConfiguration implements SqlConstants {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public DataSource dataSource;
@Bean
public JdbcCursorItemReader<Notification> reader() {
JdbcCursorItemReader<Notification> reader = new JdbcCursorItemReader<Notification>();
reader.setDataSource(dataSource);
reader.setSql(SqlConstants.SQL_GET_ALL_NOTIFICAITON_TO_BE_SENT);
reader.setRowMapper(new BeanPropertyRowMapper<>(Notification.class));
return reader;
}
@Bean
public NotificationItemProcessor notificatonProcessor() {
return new NotificationItemProcessor();
}
@Bean
public JdbcBatchItemWriter<Notification> notificationWriter() {
JdbcBatchItemWriter<Notification> writer = new JdbcBatchItemWriter<Notification>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Notification>());
writer.setSql(SqlConstants.SQL_SET_NOTIICAITON_STATUS_TO_SENT);
writer.setDataSource(dataSource);
return writer;
}
@Bean
public JdbcBatchItemWriter<Notification> exchangeWorkflowWriter() {
JdbcBatchItemWriter<Notification> writer = new JdbcBatchItemWriter<Notification>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Notification>());
writer.setSql(SqlConstants.SQL_INSERT_EXCHANGE_WORKFLOW);
writer.setDataSource(dataSource);
return writer;
}
@Bean
public JdbcBatchItemWriter<Notification> exchangeWriter() {
JdbcBatchItemWriter<Notification> writer = new JdbcBatchItemWriter<Notification>();
writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<Notification>());
writer.setSql(SqlConstants.SQL_INSERT_EXCHANGE);
writer.setDataSource(dataSource);
return writer;
}
@Bean
public DummyWriter doNothing() {
return new DummyWriter();
}
@SuppressWarnings("unchecked")
@Bean
public ItemWriter<Notification> compositeExchangeWriter() throws InstantiationException, IllegalAccessException {
BackToBackPatternClassifier classifier = new BackToBackPatternClassifier();
classifier.setRouterDelegate(new ExchangeWriterRouterClassifier());
classifier.setMatcherMap(new HashMap<String, ItemWriter<? extends Notification>>() {
{
put(ExchangeRouter.INSERT_EXCHANGE_FOR_NOTIFICATION.getActionName(), exchangeWorkflowWriter());
put(ExchangeRouter.INSERT_EXCHANGE_FOR_PACK.getActionName(), exchangeWriter());
put(ExchangeRouter.DO_NOTHING.getActionName(), doNothing());
}
});
ClassifierCompositeItemWriter<Notification> writer = new ClassifierCompositeItemWriter<Notification>();
writer.setClassifier(classifier);
return writer;
}
@Bean
public Job generatePdf(JobCompletionNotificationListener listener) throws InstantiationException, IllegalAccessException {
return jobBuilderFactory.get("generatePdf")
.incrementer(new RunIdIncrementer())
.flow(treatStock())
.end()
.build();
}
@Bean
public Step treatStock() throws InstantiationException, IllegalAccessException {
return stepBuilderFactory.get("treatStock")
.<Notification, Notification>chunk(1)
.reader(reader())
.processor(notificatonProcessor())
.writer(compositeExchangeWriter())
.build();
}
}