【发布时间】: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