@Autowired
What is Autowired?
An annotation used in the Spring Framework for
automatic injectionSpring configures relationships between objects through DI (Dependency Injection), maintaining the application's loose coupling
By using the
@Autowiredannotation, you can specify that the Spring Container automatically injects the Bean object corresponding to the field, constructor, or method parameter
Using the @Autowired annotation reduces code complexity and makes maintenance easier, since the Spring Framework automatically injects dependencies without the need to directly create or inject dependent objects
Order of Finding Dependent Objects When @Autowired is Applied
Search for a bean object with the same type
If there is 1, use that bean object
If @Qualifier is specified, the bean object must have the same value
If there are two or more bean objects with the same type and @Qualifier is not present, find a bean object with the
same nameβ If found, use that object
If there are two or more bean objects with the same type, find the bean object specified by @Qualifier
β If found, use that object
If none of the above cases apply, the container throws an Exception
Last updated