-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log warning for single optional constructor when no default constructor to fall back to [SPR-12161] #16775
Comments
Fabio Franco da Silva commented
|
Juergen Hoeller commented Constructors and injection methods differ from injection fields in that 'optional' means that the constructor/method will not be called at all if one of its dependencies is not satisfied. For the constructor case, this usually means that another constructor is supposed to be picked instead then. The problem seems to be that we're not clearly indicating the problem/solution in the case where the only constructor is marked as optional, so there is no other constructor to fall back to... In any case, as a solution, you'll have to add a fallback constructor (possibly a default constructor without arguments) . Juergen |
Juergen Hoeller commented I've decided to turn this into a logging issue: We should log a warning for a single optional constructor when there is no default constructor to fall back to, since such a constructor is effectively required according to Spring's constructor invocation semantics. To make the warning go away, one should either mark the constructor as actually required or add a default constructor without parameters to fall back to (which does not have to be annotated, just declared). Juergen |
Fabio Franco da Silva opened SPR-12161 and commented
When using Autowired annotation in constructor and the dependency is not required. Spring throws this exception "No qualifying bean of type [MyClassName] found for dependency [collection of MyClassName]: expected at least 1 bean which qualifies as autowire candidate for this dependency". But, when the annotation is changed to the field, the exception not is throwed and the application works normally.
P.S.: Sorry for my english.
Affects: 3.2.11, 4.0.7, 4.1 GA
Referenced from: commits 5cf4524, 80cec01, bf881e4
Backported to: 4.0.8, 3.2.12
The text was updated successfully, but these errors were encountered: