Spring 集成:SpringApplicationContext 是否在配置中调用@ServiceActivator?
Spring integration : does SpringApplicationContext call @ServiceActivator in config?
我正在阅读 Spring 集成源代码,我对工作流程有一些疑问:
当调用 application.run()
时,@SpringBootApplication class 是否会直接调用使用 @ServiceActivator 注释的 bean?例如在我的配置文件中我有:
@Bean
@ServiceActivator(inputChannel = test)
public MessageHandler myHandler() {
return new SomeHandler();
}
当触发 application.run()
时,将调用 SomeHandler
的方法 handleRequestMessage()
?我理解的对吗?
嗯,你要明白,这件事有两个部分:
- 配置阶段Spring 解析所有注解以在
AppplicaitonContext
中注册bean。这样,即使 @ServiceActivator
被咨询,事件驱动端点也被注册为 bean。
- Spring 集成环境的运行时部分。这里提到的端点订阅了
inputChannel
,当消息到达时,handleRequestMessage()
从 SomeHandler
触发。这就是为什么它被称为“服务激活器”。
您可能首先需要让自己熟悉 EIP:https://www.enterpriseintegrationpatterns.com/ to understand what is messaging and why there are endpoints and channels in between. Then you go to Spring Integration docs: https://docs.spring.io/spring-integration/docs/current/reference/html/index.html 并自己意识到这个框架为这个或那个 EIP 提供了一堆开箱即用的组件,这些组件可能是只需声明一些注释即可在应用程序上下文中自动注册。
我正在阅读 Spring 集成源代码,我对工作流程有一些疑问:
当调用 application.run()
时,@SpringBootApplication class 是否会直接调用使用 @ServiceActivator 注释的 bean?例如在我的配置文件中我有:
@Bean
@ServiceActivator(inputChannel = test)
public MessageHandler myHandler() {
return new SomeHandler();
}
当触发 application.run()
时,将调用 SomeHandler
的方法 handleRequestMessage()
?我理解的对吗?
嗯,你要明白,这件事有两个部分:
- 配置阶段Spring 解析所有注解以在
AppplicaitonContext
中注册bean。这样,即使@ServiceActivator
被咨询,事件驱动端点也被注册为 bean。 - Spring 集成环境的运行时部分。这里提到的端点订阅了
inputChannel
,当消息到达时,handleRequestMessage()
从SomeHandler
触发。这就是为什么它被称为“服务激活器”。
您可能首先需要让自己熟悉 EIP:https://www.enterpriseintegrationpatterns.com/ to understand what is messaging and why there are endpoints and channels in between. Then you go to Spring Integration docs: https://docs.spring.io/spring-integration/docs/current/reference/html/index.html 并自己意识到这个框架为这个或那个 EIP 提供了一堆开箱即用的组件,这些组件可能是只需声明一些注释即可在应用程序上下文中自动注册。