INT-4402: Apply global interceptors at runtime

JIRA: https://jira.spring.io/browse/INT-4402

Make `GlobalChannelInterceptorProcessor` as a `BeanPostProcessor`,
so it can apply global `ChannelInterceptor`s to any initialized channel
beans, even those created at runtime, like in case of dynamic flows with
Java DSL

**Cherry-pick to 4.3.x**

* Add `postProcessDynamicBeans` global property with `false` by default
* Rely on the `postProcessDynamicBeans` property in the
`GlobalChannelInterceptorProcessor.postProcessAfterInitialization()`
*  Add `postProcessDynamicBeans=true` to the
`GlobalChannelInterceptorTests-context.xml` to be sure in the test-case
that option works
* Document the option and effect from the global channel interceptors
This commit is contained in:
Artem Bilan
2018-02-15 11:02:28 -05:00
committed by Gary Russell
parent 2f038384ec
commit c7c6264642
7 changed files with 89 additions and 16 deletions

View File

@@ -723,6 +723,9 @@ To inject a global interceptor _BEFORE_ the existing interceptors, use a negativ
NOTE: Note that both the `order` and `pattern` attributes are optional.
The default value for `order` will be 0 and for `pattern`, the default is '*' (to match all channels).
Starting with _version 4.3.15_, you can configure a property `spring.integration.postProcessDynamicBeans = true` to apply any global interceptors to dynamically created `MessageChannel` beans.
See <<global-properties>> for more information.
[[channel-wiretap]]
===== Wire Tap

View File

@@ -208,6 +208,7 @@ spring.integration.messagingTemplate.throwExceptionOnLateReply=false <5>
spring.integration.messagingAnnotations.require.componentAnnotation=false <6>
spring.integration.readOnly.headers= <7>
spring.integration.endpoints.noAutoStartup= <8>
spring.integration.postProcessDynamicBeans=false <9>
----
<1> When true, `input-channel` s will be automatically declared as `DirectChannel` s when not explicitly found in the
@@ -237,6 +238,10 @@ These endpoints can be started later manually by their bean name via `Control Bu
The effect of this global property can be explicitly overridden by specifying `auto-startup` XML or `autoStartup` annotation attribute, or via call to the `AbstractEndpoint.setAutoStartup()` in bean definition.
_Since version 4.3.12_
<9> A boolean flag to indicate that `BeanPostProcessor` s should post-process beans registered at runtime, e.g. message channels created via `IntegrationFlowContext` can be supplied with global channel interceptors.
_Since version 4.3.15_
These properties can be overridden by adding a file `/META-INF/spring.integration.properties` to the classpath.
It is not necessary to provide all the properties, just those that you want to override.
@@ -429,7 +434,7 @@ With this endpoint using the default poller:
public class AnnotationService {
@Transformer(inputChannel = "aPollableChannel", outputChannel = "output"
poller = @Poller("myPoller")
poller = @Poller("myPoller"))
public String handle(String payload) {
...
}