Skip to content

Conversation

artembilan
Copy link
Member

Fixes #3926

Current approach for generated bean name in the MessagingGatewayRegistrar is to decapitalize simple class name, which is similar to standard AnnotationBeanNameGenerator

  • Make logic in the MessagingGatewayRegistrar based on the provided BeanNameGenerator
  • Expose an @IntegrationComponentScan.nameGenerator() attribute to allow to customize default bean name generation strategy
  • Introduce IntegrationConfigUtils.annotationBeanNameGenerator() to take a provided AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR singleton or fallback to the AnnotationBeanNameGenerator.INSTANCE
  • Use this utility in the IntegrationComponentScanRegistrar if no custom strategy is provided in the @IntegrationComponentScan
  • Use same util from the GatewayParser since there is no custom naming strategy configuration
  • Some other current Java level refactoring in the IntegrationComponentScanRegistrar and MessagingGatewayRegistrar

Comment on lines 322 to 328
The `@MessagingGateway.name()` attribute specifies a name for the target bean registered.
If it is not provided, the `@IntegrationComponentScan.nameGenerator()` (since version `6.0`) is consulted.
And if that is not provided as well, an `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` bean, provided for the application context, is used.
Otherwise, the bean name generation falls back to the `AnnotationBeanNameGenerator` which results with an uncapitalized simple class name.
In other words, the current naming strategy for gateway proxy beans is aligned with standard Spring Framework `@ComponentScan` approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `@MessagingGateway.name()` attribute specifies a name for the target bean registered.
If it is not provided, the `@IntegrationComponentScan.nameGenerator()` (since version `6.0`) is consulted.
And if that is not provided as well, an `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` bean, provided for the application context, is used.
Otherwise, the bean name generation falls back to the `AnnotationBeanNameGenerator` which results with an uncapitalized simple class name.
In other words, the current naming strategy for gateway proxy beans is aligned with standard Spring Framework `@ComponentScan` approach.
The `@MessagingGateway.name()` attribute specifies a name for the target bean that will be registered.
If it is not provided, the `@IntegrationComponentScan.nameGenerator()` (since version `6.0`) is consulted.
And, if that is not provided, an `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` bean, if present in the application context, is used.
Otherwise, the bean name generation falls back to the `AnnotationBeanNameGenerator` which results with an uncapitalized simple class name.
In other words, the current naming strategy for gateway proxy beans is aligned with standard Spring Framework `@ComponentScan` approach.

@artembilan
Copy link
Member Author

This probably can be revised when #3929 is merged, since it looks like we would need from now on only a ClassPathBeanDefinitionScanner customized to allow interfaces.
The rest can be delegated to the regular ScannedGenericBeanDefinition and in the end to a new InstantiationAwareBeanPostProcessor.
Thanks

Fixes spring-projects#3926

Current approach for generated bean name in the `MessagingGatewayRegistrar`
is to decapitalize simple class name, which is similar to standard `AnnotationBeanNameGenerator`

* Make logic in the `MessagingGatewayRegistrar` based on the provided `BeanNameGenerator`
* Expose an `@IntegrationComponentScan.nameGenerator()` attribute to allow to customize
default bean name generation strategy
* Introduce `IntegrationConfigUtils.annotationBeanNameGenerator()` to
take a provided `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` singleton
or fallback to the `AnnotationBeanNameGenerator.INSTANCE`
* Use this utility in the `IntegrationComponentScanRegistrar` if no custom strategy is provided
in the `@IntegrationComponentScan`
* Use same util from the `GatewayParser` since there is no custom naming strategy configuration
* Some other current Java level refactoring in the `IntegrationComponentScanRegistrar`
and `MessagingGatewayRegistrar`
* Alias `@MessageEndpoint.value()` with a `@Component.value()`
* Alias `@MessagingGateway.name()` with a `@MessageEndpoint.value()`
…nfiguration

directly by the `GatewayProxyInstantiationPostProcessor` and `AnnotationGatewayProxyFactoryBean`.
* The `MessagingGatewayRegistrar` logic has been migrated back to the `GatewayParser`,
but only with an XML-relevant parts
* Change the logic of the `IntegrationComponentScanRegistrar` to rely on a `ClassPathBeanDefinitionScanner`
and its `scan()` functionality since this is all what we need to trigger a `GatewayProxyInstantiationPostProcessor`
for scanned components
* Fix `GatewayProxyInstantiationPostProcessor` to call an `afterPropertiesSet()` as well
* Add a `value()` alias attribute for the `@MessagingGateway` to satisfy a name resolution from a `@Component`
* Replace annotation chain resolution logic by new `MessagingAnnotationUtils.resolveMergedAttribute()` API
* Use `MergedAnnotations` API in the `AnnotationGatewayProxyFactoryBean` to preserve a logic for attribute
resolution from the annotation hierarchy
* Add expression resolution for attribute values in the `AnnotationGatewayProxyFactoryBean`
* Make a `GatewayInterfaceTests.CustomBeanNameGenerator` as an `AnnotationBeanNameGenerator`
extension to satisfy the test logic expectations: no custom name if explicit is present
* Clean up some doc typos after merge conflict

The fix in this commit essentially resolves some old JIRA ticket: https://jira.spring.io/browse/INT-4558
@artembilan
Copy link
Member Author

Sorry, it took a bit more time than I expected: the annotation stuff has eaten my brain...

* Optimize the logic in the `AnnotationGatewayProxyFactoryBean` around
annotation attributes to plain annotation - no adaptation to maps
@garyrussell garyrussell merged commit 39bb090 into spring-projects:main Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default MessagingGateway bean name in 6.0
2 participants