[英]Spring integration inbound-channel-adapter triggered at post construct?
Suppose I have this class: 假设我有这个课:
public class MyClass {
public String myMethod() {
//...
}
}
What I want is when my application starts, to send the result that myMethod()
returns to a certain channel in Spring Integration. 我想要的是在应用程序启动时将myMethod()
返回的结果发送到Spring Integration中的某个通道。 What I have tried: 我尝试过的
<bean id="myClass" class="myPackage.MyClass"/>
<int:inbound-channel-adapter channel="channelINeedToSendTo" ref="myClass" method="myMethod">
<int:poller cron=""/> <!-- poller configuration -->
</int:inbound-channel-adapter>
Now what can I configure in poller is to call myMethod()
at a certain time, on regularly on a certain scheduling, but I wanted to be run exactly after the application started (something like @PostConstruct
). 现在,我可以在poller中配置的是在特定时间,按特定计划定期调用myMethod()
,但我希望在应用程序启动后准确运行(类似于@PostConstruct
)。 Is there a simple way achieving this, without complicated AOP techniques? 没有复杂的AOP技术,有没有简单的方法可以实现这一目标?
You can add an Event Inbound Channel Adapter to capture the ContextRefreshedEvent
Application Event; 您可以添加事件入站通道适配器以捕获ContextRefreshedEvent
应用程序事件; then wire that adapter to a <service-activator/>
that invokes myMethod()
; 然后将该适配器连接到调用myMethod()
的<service-activator/>
; the result will be on the output-channel
. 结果将在output-channel
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.