Header Ads

ad

Spring Core | Bean Wiring

Bean Wiring

Configuring beans and their properties for dependency injection in spring bean configuration file is called bean wiring.

There are two types of bean wiring :
1) Explicit wiring :-

Here we use <property>, <construtor-arg> tags for dependency injection configuration.

2) Auto wiring(Implicit wiring) :-

 Here IOC container automatically detects the dependents and inject them to the target class. Here no <property>,<constructor-arg> tags are required.

"autowire" attribute of <bean> tag is used to enable autowiring.

Limitations of Autowiring/ Implicit wiring

>> It can be used only to inject objects but not to simple values.

>> If IOC container has multiple dependents to inject then ambiguity problem may rise.

>> It kills the readability of xml file, so the bug fixing becomes very complex.

Note :-

Use autowiring only in POC projects or PILOT projects for faster application development.

There are 4 modes of performing autowiring

1) byName
2) byType
3) constructor
4) autodetect (removed from spring 3.x)

1) Explicit wiring 

1) It performs setter injection
2) For this, all target class property names and dependent class bean ids must match.
3) There is no possibility of getting ambiguity problem.






No comments