Spring container has capability of automatically injecting dependencies while initiating bean. There are 5 different modes.

You can turn on autowire feature by using following code in your XML. With this you can start using @Autowire annotation in your Java file.

<context:annotation-config />
<!-- Or -->
<bean class ="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

<bean id="application" class="com.websystique.spring.domain.Application" autowire="byName"/> 
 <!-- Application class has a applicationUser property and it will be autowired by name as there is one applicationUser Object is defined below -->

<bean id="applicationUser" class="com.websystique.spring.domain.ApplicationUser" >
    <property name="name" value="superUser"/>
</bean>

<!-- Second object ApplicationUser-->
<bean id="applicationUser2" class="com.websystique.spring.domain.ApplicationUser" >
    <property name="name" value="superUser"/>
</bean>

You can autowire class properties directly even if they are private, you can autowire fields by constructor parameters or setters parameter. What if you have two ApplicationUser object in container which one application object will use, In XML based you can just give object name but in Java class you will have to use @Qualifier(“applicationUser2”) to identify which one to pick.

@Autowired
@Qualifier ("applicationUser2")
private ApplicationUser applicationUser;

What if container doesn’t find the matching object? It will throw error, you can suppress this by using @Autowired (required=false)

@Autowired(required=false)
@Qualifier ("applicationUser2")
private ApplicationUser applicationUser;