亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring集成“沒有可用的名為'toFtpChannel'的bean”

Spring集成“沒有可用的名為'toFtpChannel'的bean”

慕村9548890 2021-11-11 18:21:06
我需要將圖像上傳到 FTP 服務器。因此,我創建了與 SessionFactory、MessageHandler 和 MessageGateway 的集成配置,用于將文件上傳到 FTP 服務器:@Configuration@IntegrationComponentScanpublic class FtpConfiguration {    @Bean    public SessionFactory<FTPFile> ftpSessionFactory() {        DefaultFtpSessionFactory defaultFtpSessionFactory = new DefaultFtpSessionFactory();        //setup        return new CachingSessionFactory<>(defaultFtpSessionFactory);    }    @Bean    @ServiceActivator(inputChannel = "toFtpChannel")    public MessageHandler handler() {        FtpMessageHandler handler = new FtpMessageHandler(ftpSessionFactory());        handler.setAutoCreateDirectory(true);        handler.setRemoteDirectoryExpression(new LiteralExpression(""));        handler.setFileNameGenerator(message -> (String) message.getHeaders().get("filename"));        return handler;    }    //to show you that I've tried both    /*@Bean    public IntegrationFlow ftpOutboundFlow() {        return IntegrationFlows.from("toFtpChannel")                .handle(Ftp.outboundAdapter(ftpSessionFactory(), FileExistsMode.REPLACE)                        .useTemporaryFileName(false)                        .fileNameExpression("headers['" + FileHeaders.FILENAME + "']")                        .remoteDirectory("")                ).get();    }*/    @MessagingGateway    public interface UploadGateway {        @Gateway(requestChannel = "toFtpChannel")        void upload(@Payload byte[] file, @Header("filename") String filename, @Header("path") String path);    }}成功構建應用程序。然后我試圖上傳一些文件:@AutowiredUploadGateway uploadGateway;@Overridepublic void uploadImage(byte[] scanBytes, String filename, String path) {    try {        uploadGateway.upload(scanBytes, filename, path);    } catch (Exception e) {        log.error("WRONG", e);    }}然后它說:“沒有名為'toFtpChannel'的bean可用” 我幾乎嘗試了每個教程,我做錯了什么?
查看完整描述

2 回答

?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

您的應用程序看起來不像真的是 Spring Boot:我們沒有看到@SpringBootApplication注釋。正是這個將啟動正確的自動配置,包括用于 Spring Integration 的自動配置。

如果您仍然不關心那里的 Spring Boot,那么您將缺少一個標準@EnableIntegration注釋:https : //docs.spring.io/spring-integration/docs/current/reference/html/overview.html#configuration-enable-一體化


查看完整回答
反對 回復 2021-11-11
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

在您可以在注釋中引用它之前,請求通道應該實際存在。聲明頻道,該問題應該消失


@Bean

public MessageChannel toFtpChannel() {

    return new DirectChannel();

}

此示例創建,DirectChannel但您可以根據您的語義選擇任何實現。


希望能幫助到你!


查看完整回答
反對 回復 2021-11-11
  • 2 回答
  • 0 關注
  • 201 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號