Hi I am newbee to Springs Framework I just want to knw what exactly Autowiring do in Spring framework?
Asked
Active
Viewed 362 times
0
-
Go through Spring docs. – AllTooSir Jul 02 '13 at 06:49
-
@TheNewIdiot I hv checked that but i didnt get it. :( – Prabhakar Manthena Jul 02 '13 at 06:50
-
check this http://stackoverflow.com/questions/3153546/how-does-autowiring-work-in-spring – Rohan Jul 02 '13 at 06:51
-
@R.S So we dont need to inject from the Application context wen we use this Autowired annotation ri8??? – Prabhakar Manthena Jul 02 '13 at 06:54
-
1@PrabhakarManthena Yes we don't need to inject from application context if we use @Autowired.But to enable @Autowired, you need to register `AutowiredAnnotationBeanPostProcessor`.http://www.mkyong.com/spring/spring-auto-wiring-beans-with-autowired-annotation/ – Rohan Jul 02 '13 at 06:59
1 Answers
0
Consider an example of Spring beans without autowiring first.
For e.g. Consider a class Customer
class Customer {
private Person person;
public Customer(Person person) {
this.person = person;
}
public void setPerson(Person person) {
this.person = person;
}
}
And class Person
class Person {
}
In spring bean configuration file the entries will be,
<bean id="customer" class="...Customer>
<property name="person" ref="person" />
</bean>
<bean id="person" class="...Person" />
Using spring bean autowiring you can avoid writing the property tag inside the bean, in four different ways.
- Auto wiring by name
In this case the name of the property in Customer class must match with the id of the bean which you want to autowire i.e 'person'
Hence the entry of the Customer bean can be re-written as
<bean id="customer" class="...Customer" autoWire="byName" />
Similarly there are other auto wiring modes in spring, auto wiring byType, constructor, autodetect. You can refer link http://www.mkyong.com/spring/spring-auto-wiring-beans-in-xml/

Hetal Rachh
- 1,393
- 1
- 17
- 23