Spring Series — Setter Injection
Previous part of the series — Dependency Injection:
Setter injection is a pattern that describes injecting dependencies by calling setter methods on a class.
We can revisit this definition but before we do, let’s create a new coach implementation and see what it looks like.
Here we have created our SwimCoach
implementation. We can see that it has a dependency and that we now assign the fortuneService
variable with a setter method and not in our constructor.
Note: In the mySwimCoach
bean we can see the property
tag. This tag is what lets Spring know to use the name setFortuneService
when creating the SwimCoach
.
Let’s continue this example further by repeating the process for injecting attributes for our Coach
.