Setter Injection:
After instantiating you’re Bean with no-argument constructor or no argument static factory method setter methods on bean can be invoked.
public class Sample {
// the sample has a dependency on the item
private Item item;
// a setter method so that the Spring container can 'inject' a item
public void setMoveFinder(Item item)
{
this.item = item;
}
}
Constructor Injection:
The following code is the example of the Constructor Injection.
public class Sample
{
// the sample has a dependency on the item
private Item item;
// a setter method so that the Spring container can 'inject' a item
public Sample(Item item)
{
this.item = item;
}
}