Why is a default constructor needed for injection
Hello,
I'm new to the spring framework and I've got a question:
When I want to use Dependency Injection, why is it so important that the classes whose properties get injected have a default constructor? I can understand that setters are needed, but I don't know why there must be a default constructor, because aspects should be able to wrap around any constructor, not just the default ones (in AspectJ, you can use wildcards for parameter lists and so on).
Is there any special reason? Or does some way exist to use Dependency Injection with a class that has only parameterized constructors? In my case, there are some classes where it wouldn't be a good thing to offer default constructors.
Thanks in advance
ZeHa
No public constructor required
Just a quick follow on.
It is true you need a default contructor so Spring can instantiate it.
It does not however have to be a public contructor.
This is useful if you want to prevent any programmer from instantiation the default contructor.