Dependency Injection in Spring

To set the item attribute in the example above, we can use metadata. Then, the container will read this metadata and use it to assemble beans at runtime.

Dependency Injection in Spring can be done through constructors, setters or fields.

Constructor-Based Dependency Injection

Setter-Based Dependency Injection

Field-Based Dependency Injection

Autowiring Dependencies