You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* INT-4569: Disallow beans override in DSL
JIRA: https://jira.spring.io/browse/INT-4569
* Thorw `BeanDefinitionOverrideException` from the
`IntegrationFlowBeanPostProcessor` when it detects existing bean and it
is not the same object we try to register from the DSL
* Document limitations about `prototype` beans
* Some polishing in the DSL chapter of the docs
* * Fix algorithm in the `IntegrationFlowBeanPostProcessor.noBeanPresentForComponent()`
* * Polishing dsl.adoc
* Call `BeanFactory.initializeBean()` for existing beans if they are
`prototype`
* * Code formatting in the `ManualFlowTests`
Copy file name to clipboardExpand all lines: spring-integration-core/src/main/java/org/springframework/integration/dsl/context/IntegrationFlowBeanPostProcessor.java
This will fail at runtime with a `ClassCastException` because the lambda doesn't retain the argument type and the framework will attempt to cast the payload to a `Message<?>`.
130
130
131
131
Instead, use:
132
132
133
-
====
134
133
[source, java]
135
134
----
136
135
.(Message.class, m -> newFooFromMessage(m))
137
136
----
138
137
====
139
138
139
+
[[bean-definitions-override]]
140
+
.Bean Definitions override
141
+
[IMPORTANT]
142
+
====
143
+
The Java DSL can register beans for the object defined in-line in the flow definition, as well as can reuse existing, injected beans.
144
+
In case of the same bean name defined for in-line object and existing bean definition, a `BeanDefinitionOverrideException` is thrown indicating that such a configuration is wrong.
145
+
However when you deal with `prototype` beans, there is no way to detect from the integration flow processor an existing bean definition because every time we call a `prototype` bean from the `BeanFactory` we get a new instance.
146
+
This way a provided instance is used in the `IntegrationFlow` as is without any bean registration and any possible check against existing `prototype` bean definition.
147
+
However `BeanFactory.initializeBean()` is called for this object if it has an explicit `id` and bean definition for this name is in `prototype` scope.
148
+
====
149
+
140
150
[[java-dsl-channels]]
141
151
=== Message Channels
142
152
@@ -316,7 +326,7 @@ It avoids inconvenient coding using setters and makes the flow definition more s
316
326
Note that you can use `Transformers` to declare target `Transformer` instances as `@Bean` instances and, again, use them from `IntegrationFlow` definition as bean methods.
317
327
Nevertheless, the DSL parser takes care of bean declarations for inline objects, if they are not yet defined as beans.
318
328
319
-
See [https://docs.spring.io/spring-integration/api/org/springframework/integration/dsl/Transformers.html] in the Javadoc for more information and supported factory methods.
329
+
See https://docs.spring.io/spring-integration/api/org/springframework/integration/dsl/Transformers.html[Transformers] in the Javadoc for more information and supported factory methods.
320
330
321
331
Also see <<java-dsl-class-cast>>.
322
332
@@ -789,15 +799,18 @@ public IntegrationFlow evenFlow() {
789
799
}
790
800
----
791
801
802
+
{empty} +
792
803
In this case, when you need to receive a reply from such a sub-flow and continue the main flow, this `IntegrationFlow` bean reference (or its input channel) has to be wrapped with a `.gateway()` as shown in the preceding example.
793
804
The `oddFlow()` reference in the preceding example is not wrapped to the `.gateway()`.
794
805
Therefore, we do not expect a reply from this routing branch.
795
806
Otherwise, you end up with an exception similar to the following:
796
807
797
-
[source]
798
-
----
799
-
Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (org.springframework.integration.router.MethodInvokingRouter@7965a51c) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
0 commit comments