Update doc about constructor injection

Closes gh-8392
This commit is contained in:
Kazuki Shimizu
2017-02-24 12:04:29 +09:00
committed by Stephane Nicoll
parent 627edc0f7a
commit fa4ecff9e0

View File

@@ -590,6 +590,24 @@ required `RiskAssessor` bean.
}
----
And if a bean has one constructor, you can omit the `@Autowired`.
[source,java,indent=0]
----
@Service
public class DatabaseAccountService implements AccountService {
private final RiskAssessor riskAssessor;
public DatabaseAccountService(RiskAssessor riskAssessor) {
this.riskAssessor = riskAssessor;
}
// ...
}
----
TIP: Notice how using constructor injection allows the `riskAssessor` field to be marked
as `final`, indicating that it cannot be subsequently changed.