我有8个文件,我想上传到一个ftp服务器使用sftp在 Spring 批处理。我无法配置tasklet,如果有人能告诉我怎么做的话。此外,文件名应与本地文件名保持相同。我刚到Spring,所以请帮帮我。
@Configuration
public class FTPSonfigurations {
@Bean
public DefaultSftpSessionFactory gimmeFactory(){
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost("");
factory.setUser("");
factory.setPassword("");
return factory;
}
@Bean
@ServiceActivator(inputChannel = "uploadfile")
SftpMessageHandler uploadHandler(DefaultSftpSessionFactory factory){
SftpMessageHandler messageHandler = new SftpMessageHandler(factory);
messageHandler.setRemoteDirectoryExpression(new LiteralExpression("/upload/ "));
return messageHandler;
}
}
@MessagingGateway
public interface UploadMessagingGateway {
@Gateway(requestChannel = "uploadfile")
public void uploadFile(File file);
}
public class MyTasklet implements Tasklet {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
//What to do here???
return null;
}
}
1条答案
按热度按时间wfveoks01#
只需将网关自动连接到tasklet并调用它。