Commit fa4ecff9 authored by Kazuki Shimizu's avatar Kazuki Shimizu Committed by Stephane Nicoll

Update doc about constructor injection

Closes gh-8392
parent 627edc0f
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment