The Spring framework provides autowiring feature to enable the object dependency implicitly. @Autowired and @Qualifier are the two different autowire annotations to achieve the automatic dependency injunction in Spring.

Spring @Autowired annotation :

In Spring, we can use @Autowired annotation to tell the IOC container, the dependency of the properties will be injected by the container itself.

The @Autowired and @Qualifier annotations can be used on top of a field, setter methods or on top of a constructor of a class.

If we declare the autowire annotation on top of the method or property, the IOC container always searches whether a dependency property name and the bean id in XML are matched or not, if those are matched the automatic dependency injection will happen.

@Autowired with Setter :

[java]

public class Book {
    private Author author;

    @Autowired
    public void setAuthor(Author author) {
        this.author = author;
    }
}

[/java]

Xml Configuration :

<bean id="author" class="com.onlinetutorialspoint.beans.Author">   
   <property name="name" value="OnlineTutorialsPoint" />       
   <property name="name" value="Hyderabad" />
</bean>

@Autowired with Constructor :

We can use the Autowired annotation, on top of the constructor. Here is the syntax:

[java]

public class Book {
    private Author author;

    @Autowired
    public Book(Author author) {
        this.author = author;
    }
}

[/java]

@Autowired with Property :

We can use the Autowired annotation, on top of the property. Here is the syntax:

[java]

public class Book {
    @Autowired
    private Author author;
}

[/java]

Xml Configuration :

<bean id="author" class="com.onlinetutorialspoint.beans.Author">
   <property name="name" value="OnlineTutorialsPoint" />     
   <property name="name" value="Hyderabad" />
</bean>

Spring @Qualifier annotation :

@Qualifier is one of the autowiring property in spring. If a dependency class is configured for more than once in spring configuration file, the IOC container will throw the Exception for bean ambiguity. In order to resolve the ambiguity, we can use @Qualifier annotation along with the  @Autowired annotation. Example:

[java]

public class Book {
    private Author author;
    @Autowired
    @Qualifier("author2")
    private Author author;

    public void setAuthor(Author author){
        this.author = author
    }
}

[/java]

Xml Configuration :

<bean id="author" class="com.onlinetutorialspoint.beans.Author">
   <property name="name" value="OnlineTutorialsPoint" />
   <property name="name" value="Hyderabad" />
</bean>

Spring @Value annotation :

@Value annotation is used to assign a value to a property. It is only used to assign a value for a simple type property (int, float etc..) in a bean class. @Value annotation tells IOC container, that read the value of a key from resource bundle and initializes a simple property with that value. Example:

[java]

public class Sample {
    @Value("${k1}")
    private int i;
}
[/java]

At runtime, IOC container will initialize the “i” property with the value of “k1” of the resource bundle. Here resource bundle can be a properties file. In the properties file, if the k1 value is 100 then in runtime IOC container assign the 100 value to “i” property. Here is the complete example of Spring Expression Handling.