public class ABC {
@Autowired
@Qualifier("toSftpChannel")
public MessageChannel toSftpChannel;
public void handleRequest(String id) {
RestTemplate restTemplate = new RestTemplate();
DocumentumDataObject dataObj = restTemplate.getForObject(
"url" + id,
DataObject.class);
String decodedData = new String(Base64.getDecoder().decode(dataObj.getFileEncodedString()));
String fileName = "dctm_gsnfr_" + id + ".pdf";
System.out.println("channel: " + toSftpChannel);
this.toSftpChannel.send(MessageBuilder.withPayload(decodedData).setHeader(FileHeaders.FILENAME, fileName).build());
}
}
以上代码不起作用。对于'toSftpChannel'自动装配的bean,我没有得到这样的bean MessageChannel。
但是下面的代码可以:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ABCTest{
@Autowired
@Qualifier("toSftpChannel")
public MessageChannel toSftpChannel;
@Test
public void sftpOutboundFlowTest() {
System.out.println("channel: " + toSftpChannel);
this.toSftpChannel
.send(MessageBuilder.withPayload(payload)
.setHeader(FileHeaders.FILENAME, fileName)
.build());
}
}
请考虑以下代码是其余的bean:
@Configuration
@EnableAutoConfiguration
@IntegrationComponentScan
public class ASDF {
@Autowired
private SftpSessionHandler sftpSessionHandler;
@Bean
public IntegrationFlow sftpOutboundFlow() {
return IntegrationFlows.from("toSftpChannel")
.handle(Sftp.outboundAdapter(this.sftpSessionHandler.sftpSession, FileExistsMode.FAIL)
.useTemporaryFileName(false)
.remoteDirectory("/")
).get();
}
@Component
public class SftpSessionHandler {
public DefaultSftpSessionFactory sftpSession;
public SftpSessionHandler() {
sftpSession = new DefaultSftpSessionFactory(true);
sftpSession.setHost("1.2.3.4");
sftpSession.setPort(22);
sftpSession.setUser("asdf");
sftpSession.setPassword("asdf");
sftpSession.setAllowUnknownKeys(true);
}
}
总体流程是
我是春季整合的新手(2周)。我已经看过您在YouTube上进行的技术讲座,并发现它很有启发性。先感谢您。 :)