@Autowired kích hoạt tự động inject dependency — Spring tự resolve và inject.
- Có thể dùng trên: constructor, setter, field.
- Mặc định: wire by type (theo kiểu).
- Nếu có nhiều bean cùng kiểu, dùng
@Qualifier("name")để chỉ định. - Dependencies optional:
@Autowired(required=false)không throw lỗi nếu không có bean. - Khuyến nghị: Constructor injection (rõ dependencies, dễ test); tránh Field injection (hidden dependencies, khó mock trong unit test).