@Scope("step")
public class MajorItemReader implements InitializingBean{
private List<YourItem> yourItems= null;
@Autowired
private MyService provider;
public YourItem read() {
if ((yourItems!= null) && (yourItems.size() != 0)) {
return yourItems.remove(0);
}
return null;
}
//Reading Items from Service
private void reloadItems() {
this.yourItems= new ArrayList<YourItem>();
// use the service to provide your Items
if (yourItems.isEmpty()) {
yourItems= null;
}
}
public MyService getProvider() {
return provider;
}
public void setProvider(MyService provider) {
this.provider = provider;
}
@Override
public void afterPropertiesSet() throws Exception {
reloadItems();
}
}
三,。创建自己的物品处理器
public class MyProcessor implements
ItemProcessor<YourItem, YourItem> {
@Override
public YourItem process(YourItem arg0) throws Exception {
// Apply any logic to your Item before transferring it to the writer
return arg0;
}
}
四,。创建自己的作者:
public class MyWriter{
@Autowired
@Qualifier("ftpChannel")
private MessageChannel messageChannel;
public void write(YourItem pack) throws IOException {
//create your file and from your Item
File file = new File("the_created_file");
// Sending the file via Spring Integration Ftp Channel
Message<File> message = MessageBuilder.withPayload(file).build();
messageChannel.send(message);
}
# 1 楼答案
您可以将Spring集成ftp/sftp与Spring批处理结合使用:
一,。Spring集成Ftp配置:
二,。创建您的阅读器并自动连接服务,以便在需要时提供您的物品:
三,。创建自己的物品处理器
四,。创建自己的作者:
五,。批处理配置:
六,。另一个用于配置作业的ApplicationContext文件:
七,。最后配置启动器以启动作业: