-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Improve documentation for @Autowired constructors #23263
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
Comments
Related to gh-21832 |
Prior to this commit, there was some ambiguity surrounding semantics for @Autowired constructors and `required = true`, especially for multiple @Autowired constructors. This commit improves the documentation in the Javadoc for @Autowired as well as in the reference manual. Closes gh-23263
Prior to this commit, there was some ambiguity surrounding semantics for @Autowired constructors and `required = true`, especially for multiple @Autowired constructors. This commit improves the documentation in the Javadoc for @Autowired as well as in the reference manual. Closes gh-23263
@farazdurrani, thanks for raising the issue. The improved documentation can be seen in the latest snapshot for the reference manual and Javadoc. |
No problem. The new wordings are clear. Thank you. |
Hello @sbrannen , I think that the problem is still there. In the new docs (https://docs.spring.io/spring/docs/5.2.0.BUILD-SNAPSHOT/spring-framework-reference/core.html#beans-autowired-annotation) we found:
I think that "at least one constructor must be annotated [...]" is not correct. According to the container behavior, just one constructor must be annotated with |
@ElmehdiBenh, thanks for pointing that out! I've opened #24838 to improve the documentation for such scenarios. |
@sbrannen , thanks to you ; |
When multiple constructors are marked by
@Autowired
, it doesn't work. Although Spring documentation clearly says that it should:I get this error when I mark multiple constructors with @Autowired with one being
required = true
and other being marked asrequired = false
:This is the code:
I have created a simple github repo to reproduce the issue.
OS: Ubuntu 18.04
JDK 8.
Spring Boot version 2.1.6
The text was updated successfully, but these errors were encountered: