GH-1083: Disallow reuse bean name for bindings #1084
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1083
By default Spring Framework allows beans overriding via the same name.
The binding target definitions (
@Input
and@Output
) populate beans as welland when we use the same name for target we end up with unexpected behavior
but without errors.
Since it isn't so obvious via Spring Framework bean definition DSLs
(XML or Java & Annotations) how to override beans with the same name,
that is absolutely easy to use the same value for
@Input
and@Output
definitions even in different binding interfaces.
That's hard to analyze fro the target application since mostly
@Input
and@Output
produceMessageChannel
beans.BeanDefinitionStoreException
when we meet existingbean definition for the same name
@Input
and@Output
to explain that theirvalue
is a bean name, as well as destination by default
Since
@EnableBinding
is@Inherited
, the inheritor picks up it from thesuper class during configuration class parsing.
The parsing process logic is such that after the root class we go to parse its
super classes, and therefore come back to the
@EnableBinding
again.In this case we process all the
@Import
s one more time and collect them tothe root
configurationClass
.Essentially we get a duplication for the
ImportBeanDefinitionRegistrar
ssuch as
BindingBeansRegistrar
.The last one parsed
@EnableBinding
and registers appropriate beans for the@Input
and@Output
, as well as for the binding interface -BindableProxyFactory
.But since we have it twice in the
configurationClass
we end up withBeanDefinitionStoreException
mentioned before.That's how Spring Framework works with inheritance for configuration classes
and that's may be why it allows to override beans by default
@EnableBinding
one more time if the bean definition forbinding interface is already present in the
registry
AggregateWithMainTest
do not process@ComponentScan
what causespicking up the configuration classes for children contexts in the aggregation
testBindableProxyFactoryCaching()
do not registerSource
andProcessor
in the same application context because both of them cause registration for the
Source.OUTPUT
bean