Spring。如何将一些变量传递给 service-activator 中的方法?
Spring. How to pass some variable to method in service-activator?
我是 Spring 的新手,但我正在努力理解它。所以现在我尝试创建 RSS reader,但是 Google 中的所有示例都太过分了,我不理解它们。
到目前为止我有豆子 xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:feed="http://www.springframework.org/schema/integration/feed"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/feed
http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">
<int:channel id="inputRssFeedChannel"/>
<feed:inbound-channel-adapter id="news"
channel="inputRssFeedChannel"
url="http://feeds.feedburner.com/Techcrunch">
<int:poller fixed-rate="5000"/>
</feed:inbound-channel-adapter>
<int:service-activator input-channel="inputRssFeedChannel"
ref="rssPrintOutService"
method="printRss"/>
<bean id="rssPrintOutService" class="MyApp.RssHandler"/>
</beans>
和 RssHandler class:
public class RssHandler {
private static final Logger theLogger = LoggerFactory.getLogger(RssHandler.class);
public void printRss() {
System.out.println("gfgfgfgfgffgfgfg");
}
}
代码工作正常我每 5 秒得到 "gfgfgfgfgffgfgfg"。但我无法理解如何将一些变量(Rss 条目)传递给 RssHandler 以处理标题、日期等并在那里打印?
Spring 集成将来自特定通道的消息传递给处理程序。所以你可以尝试这样的事情:
public class RssHandler {
private static final Logger theLogger = LoggerFactory.getLogger(RssHandler.class);
public void printRss(Message m) { // The Message Object is in the spring integration packages or in the spring core packages depending on the version
System.out.println(m);
}
}
我是 Spring 的新手,但我正在努力理解它。所以现在我尝试创建 RSS reader,但是 Google 中的所有示例都太过分了,我不理解它们。 到目前为止我有豆子 xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:feed="http://www.springframework.org/schema/integration/feed"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/feed
http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd">
<int:channel id="inputRssFeedChannel"/>
<feed:inbound-channel-adapter id="news"
channel="inputRssFeedChannel"
url="http://feeds.feedburner.com/Techcrunch">
<int:poller fixed-rate="5000"/>
</feed:inbound-channel-adapter>
<int:service-activator input-channel="inputRssFeedChannel"
ref="rssPrintOutService"
method="printRss"/>
<bean id="rssPrintOutService" class="MyApp.RssHandler"/>
</beans>
和 RssHandler class:
public class RssHandler {
private static final Logger theLogger = LoggerFactory.getLogger(RssHandler.class);
public void printRss() {
System.out.println("gfgfgfgfgffgfgfg");
}
}
代码工作正常我每 5 秒得到 "gfgfgfgfgffgfgfg"。但我无法理解如何将一些变量(Rss 条目)传递给 RssHandler 以处理标题、日期等并在那里打印?
Spring 集成将来自特定通道的消息传递给处理程序。所以你可以尝试这样的事情:
public class RssHandler {
private static final Logger theLogger = LoggerFactory.getLogger(RssHandler.class);
public void printRss(Message m) { // The Message Object is in the spring integration packages or in the spring core packages depending on the version
System.out.println(m);
}
}