We can implement dependency injection with:
https://www.baeldung.com/properties-with-spring
https://reflectoring.io/constructor-injection/
- constructor-based injection
@Component class Sandwich { private Topping toppings; private Bread breadType; @Autowired Sandwich(Topping toppings, Bread breadType) { this.toppings = toppings; this.breadType = breadType; } }
- setter-based injection
@Component class Cookie { private Topping toppings; @Autowired void setTopping(Topping toppings) { this.toppings = toppings; } }
- field-based injection.
@Component class Pizza { @Autowired private Topping toppings; }
No comments:
Post a Comment