- Building Applications with Spring 5 and Vue.js 2
- James J. Ye
- 70字
- 2025-04-04 16:05:51
Dependency injection
To wire up dependencies, we can use these two annotations provided by Spring—the @Required annotation and the @Autowired annotation. We can apply the @Required annotation to setter methods and the @Autowired annotation to constructor, methods, as well as fields.
To sum up, in Spring, there are three ways to inject dependencies:
- Constructor-based injection
- Setter-based/method-based injection
- Field-based injection.