我使用 spring 和 spring-integration。我需要为 Feed 解析创建动态 SourcePollingChannelAdapter
,并在 Spring 上下文中注册。
QueueChannel channel = (QueueChannel) context.getBean("rssFeedChannel");
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setApplicationContext(context);
adapter.setBeanName("adapter.1");
FeedEntryMessageSource source = new FeedEntryMessageSource(new URL("https://spring.io/blog.atom"), "news");
source.setApplicationContext(context);
source.setBeanName("source");
adapter.setSource(source);
adapter.setOutputChannel(channel);
adapter.setTrigger(new PeriodicTrigger(1000));
adapter.start();
我的应用程序配置:
<int:poller default="true" fixed-rate="5000"/>
<int:channel id="rssFeedChannel">
<int:queue capacity="40"/>
</int:channel>
<file:outbound-channel-adapter id="file" mode="APPEND" charset="UTF-8" directory="/tmp/si" filename-generator-expression="'SpringBlog'"/>
<!-- With this work -->
<!--<feed:inbound-channel-adapter id="news" channel="rssFeedChannel" url="https://spring.io/blog.atom">-->
<!--<int:poller fixed-rate="5000"/>-->
<!--</feed:inbound-channel-adapter>-->
<int:transformer input-channel="rssFeedChannel" expression="payload.title + ' @ ' + payload.link + '#{systemProperties['line.separator']}'" output-channel="file"/>
但没有任何内容写入文件。请帮助修复错误。
最佳答案
您也必须将
FeedEntryMessageSource
设置为 bean。applicationContext
注入(inject)。您忘记调用
adapter.afterPropertiesSet()
。顺便说一句,FeedEntryMessageSource
实例也是如此。
请从另一方面分享您对采用这种手动方式的想法。为什么不依赖标准的控制反转原理?
关于java - SourcePollingChannelAdapter 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31574395/