XML config ignores autowire="no"
#33919
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: waiting-for-triage
An issue we've not yet triaged or decided on
We've got an application that uses a lot of XML wiring - since it dates back to before Java config was a thing.
We've recently discovered that Spring is autowiring in beans when we didn't expect it to - we'd got a typo in a constructor argument name and instead of an error things were still running.
I've since reproduced this in a trivial application - which is attached.
autowire-demo.zip
In this, we've got:
ServiceB
classServiceA
class that requires an instance ofServiceB
ServiceA
. (This was simply to be able to test the wiring)spring.xml
context file for constructingServiceA
andServiceB
.However, you'll notice that in
spring.xml
we've got this:So the
ServiceA
instance has explicitly gotautowire="no"
on it, but is missing theconstructor-arg
that it needs.If you run this then you will get a working service. Spring is autowiring
serviceB
intoserviceA
even though it shouldn't.In a similar manner - which I assume is related but I don't know for certain - we've noticed that if the constructor argument is a
List
(or probably other collection types) and it's missing from the XML then Spring autowires in an empty collection instead of erroring. This is actually worse since at least with the above it's probably the case that there's only one candidate and so the right thing will happen by luck. With the list case, you're definitely getting the wrong behaviour.Unfortunately this now means that we might have some missing/broken wiring and Spring isn't alerting us to the issue.
Cheers
The text was updated successfully, but these errors were encountered: