Skip to content

Make ChannelInitializer as dependency bean in the AbstractConsumerEndpointParser #9931

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
artembilan opened this issue Mar 28, 2025 · 0 comments

Comments

@artembilan
Copy link
Member

See more info in the spring-projects/spring-boot#44873.

The AbstractConsumerEndpointParser produces a ConsumerEndpointFactoryBean which has to be initialized when BeanFactory requests a bean type. If inputChannel is not present in the BeanFactory that leads to the problem.

Making the IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME as dependency on such an endpoint bean definition should trigger the ChannelInitializer to be initialized. Therefore all the auto-create channel candidates will be created upfront.

Side task.

Revise IntegrationConfigUtils.autoCreateDirectChannel() to use registerSingleton() instead this this functionality is called at runtime from that ChannelInitializer.afterPropertiesSet().

@artembilan artembilan added this to the 6.5.0-RC1 milestone Mar 28, 2025
@artembilan artembilan self-assigned this Mar 28, 2025
spring-builds pushed a commit that referenced this issue Mar 28, 2025
Fixes: #9931
Issue link: #9931

If no message channel bean is declared explicitly, the XML parser for endpoints
register such a candidate into the global `ChannelInitializer`.
This way, the channel is created when this bean is initialized.
However, there are cases when endpoint bean could be called before `ChannelInitializer` initialization.

* Add `consumerEndpointBuilder.addDependsOn(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);`
into the `AbstractConsumerEndpointParser` to ensure that `ChannelInitializer` bean is initialized
before the called endpoint bean.
* Adjust `ChannelInitializer` logic to use `registerSingleton()` API instead of `registerBeanDefinition()`
since the last one may cause problems with beans cache when this API is called at runtime.

(cherry picked from commit c9e3de8)
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants