【问题标题】:Messaging exception: org.springframework.messaging.MessageDeliveryException in sftp outbound-channel-adapter消息异常:sftp outbound-channel-adapter 中的 org.springframework.messaging.MessageDeliveryException
【发布时间】:2015-10-18 10:50:09
【问题描述】:

消息异常:org.springframework.messaging.MessageDeliveryException:Dispatcher 没有频道“org.springframework.web.context.WebApplicationContext:/.sftpChannel”的订阅者。嵌套异常是 org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

我正在尝试将文件从本地服务器发送到远程服务器。

我的应用上下文在下面

 <bean id="startupBean" class="com.SchedulerImpl" init-method="run"/>
 <bean id="applicationContextProvider" class="com.ApplicationContextProvider"></bean>

 <bean id="sftpSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <constructor-arg ref="defaultSftpSessionFactory" />
</bean>
    <bean id="defaultSftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${destination.host}"/>
        <property name="privateKey" value="${destination.privateKey}"/>
        <property name="privateKeyPassphrase" value="${destination.privateKeyPassphrase}"/>
        <property name="port" value="${destination.port}"/>
        <property name="user" value="${destination.user}"/>
        <property name="sessionConfig" ref="props"/>
    </bean>

     <util:properties id="props">
            <prop key="PreferredAuthentications">publickey</prop>
        </util:properties>  
    <int:channel id="sftpChannel"/>

    <int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" 
                                        session-factory="sftpSessionFactory"
                                        channel="sftpChannel" 
                                        auto-startup ="false"
                                        charset="UTF-8" 
                                        remote-directory="/destinationFolder/"
                                        remote-file-separator="/">
     </int-sftp:outbound-channel-adapter>

     <int:publish-subscribe-channel id="contextRefreshEvents"/>

     <int:outbound-channel-adapter channel="contextRefreshEvents"
                            expression="sftpOutboundAdapter.start()" />

所以我在 sftp 类的代码中得到了相同的 applicationContext 实例:

ApplicationContext 上下文 = appContext.getApplicationContext();

MessageChannel sftpChannel = (MessageChannel)context.getBean("sftpChannel");

和@Autowired 私有ApplicationContextProvider appContext; 在同一个 sftp 类中。

还有另一个类 ApplicationContextProvider 实现了 ApplicationContextAware,它可以帮助我获取当前的 ApplicaitonContext。

我不明白为什么找不到订阅者。 我已经把自动启动=假。 获取当前 sftpChannel bean 的正确方法是什么,它给了我相同的 applicationContext 实例。

如果我做 appContext = new classpathxmlapplicationcontext(applicationcontext.xml ) 我在 startupBean 中遇到错误,所以我不想这样做。

现在我正在实现 ApplicationContextAware,我得到消息异常。

谁能帮帮我?

我正在使用弹簧 3

【问题讨论】:

    标签: spring spring-integration sftp


    【解决方案1】:

    你已经从你的脑海中分享了很多,最后你的问题变得一团糟。

    让我从另一面解释发生了什么。

    由于&lt;int-sftp:outbound-channel-adapter&gt; 上有auto-startup ="false",任何sendsftpChannel 都会导致该异常,直到您启动该适配器。

    从另一面我看到你这样做了,虽然我们看不到是谁发起了contextRefreshEvents消息,但我们相信你是&lt;int-event:inbound-channel-adapter&gt;

    还有一点,你没有向我们展示file from local。好的,我猜是&lt;int-file:inbound-channel-adapter&gt;。这是可轮询的,并在应用程序启动后立即开始轮询本地主管。所以,这可能会导致Dispatcher has no subscribers,因为sftpOutboundAdapter还没有启动。

    请告诉我,如果我的推理方式有误,但您预期会有所不同。

    更新

    要以编程方式启动端点(或任何其他Lifecycle 组件),您应该将其inject 提供给您的服务:

    @Autowired
    @Qualifier("sftpOutboundAdapter")
    private Lifecycle sftpOutboundAdapter;
    
    ....
    
    sftpOutboundAdapter.start();
    

    【讨论】:

    • 感谢您的回复,如果我没有 在 applicationContext 中,如何从代码启动出站适配器?
    • 现在我得到错误:消息异常:org.springframework.messaging.MessagingException:;嵌套异常是 org.springframework.messaging.MessagingException: 获取池项失败;嵌套异常是 java.lang.IllegalStateException: failed to create SFTP Session 这是否意味着我需要做 ---> @Autowired @Qualifier("sftpSessionFactory") private Lifecycle sftpSessionFactory;和 sftpSessionFactory.start();内部代码?
    猜你喜欢
    • 2017-04-28
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多