GH-3926: BeanNameGenerator for @MessagingGateway (#3927)
* GH-3926: BeanNameGenerator for @MessagingGateway Fixes https://github.com/spring-projects/spring-integration/issues/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` * * Meta-annotate `@MessagingGateway` with a `@MessageEndpoint` * Alias `@MessageEndpoint.value()` with a `@Component.value()` * Alias `@MessagingGateway.name()` with a `@MessageEndpoint.value()` * * Remove unused imports * * Replace `MessagingGatewayRegistrar` parsing logic for annotation configuration 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 * * Remove redundant `MessagingAnnotationUtils.resolveMergedAttribute()` * Optimize the logic in the `AnnotationGatewayProxyFactoryBean` around annotation attributes to plain annotation - no adaptation to maps
This commit is contained in:
@@ -322,6 +322,10 @@ Starting with version 6.0, an interface with the `@MessagingGateway` can also be
|
||||
Starting with version 6.0, `@MessagingGateway` interfaces can be used in the standard Spring `@Import` configuration.
|
||||
This may be used as an alternative to the `@IntegrationComponentScan` or manual `AnnotationGatewayProxyFactoryBean` bean definitions.
|
||||
|
||||
The `@MessagingGateway` is meta-annotated with a `@MessageEndpoint` since version `6.0` and the `name()` attribute is, essentially, aliased to the `@Compnent.value()`.
|
||||
This way the bean names generating strategy for gateway proxies is realigned with the standard Spring annotation configuration for scanned and imported components.
|
||||
The default `AnnotationBeanNameGenerator` can be overridden globally via an `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` or as a `@IntegrationComponentScan.nameGenerator()` attribute.
|
||||
|
||||
NOTE: If you have no XML configuration, the `@EnableIntegration` annotation is required on at least one `@Configuration` class.
|
||||
See <<./overview.adoc#configuration-enable-integration,Configuration and `@EnableIntegration`>> for more information.
|
||||
|
||||
|
||||
@@ -114,7 +114,10 @@ The Messaging Gateway interface method can now return `Future<Void>` and `Mono<V
|
||||
|
||||
Alongside with a `@MessagingGateway` annotation the interface can also be marked with a `@Primary`.
|
||||
|
||||
`@MessagingGateway` interfaces can now be `@Import`ed into a configuration.
|
||||
`@MessagingGateway` interfaces can now be use as an `@Import` resources for configuration.
|
||||
|
||||
The default naming strategy for gateway proxy beans can be customized via `@IntegrationComponentScan.nameGenerator()` attribute.
|
||||
If `AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR` bean is present, it is consulted otherwise before falling back to the `AnnotationBeanNameGenerator`.
|
||||
|
||||
See <<./gateway.adoc#gateway, Messaging Gateway>> for more information.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user