autowire byType vs byName

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-05-11
I was reading folowing lines and I did not understand clearly.

By using byName autowiring, you are telling the container to consider all properties
of the CourseServiceImpl and look for beans declared with the same name as
the property. In this case, two properties, courseDao and studentService, are eligible
for autowiring through setter injection. If beans are declared in the wiring
file with the names courseDao and studentService, those beans will be wired to
courseDao and studentService, respectively.Autowiring using byType works in a similar way to byName, except that instead of
considering a propertys name, the propertys type is examined. For example, if the
courseService beans autowire is set to byType instead of byName, the container will
search itself for a bean whose type is matches
Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
Question by:gudii9
LVL 92

Accepted Solution

objects earned 668 total points
ID: 35695105
LVL 47

Assisted Solution

for_yan earned 664 total points
ID: 35695121
I think this is a good explantion of autowiring byName and byType:

Autowiring by property name. This option will inspect the BeanFactory and look for a bean named exactly the same as the property which needs to be autowired. For example, if you have a bean definition which is set to autowire by name, and it contains a master property (that is, it has a setMaster(...) method), Spring will look for a bean definition named master, and use it to set the property.

Allows a property to be autowired if there is exactly one bean of the property type in the BeanFactory. If there is more than one, a fatal exception is thrown, and this indicates that you may not use byType autowiring for that bean. If there are no matching beans, nothing happens; the property is not set. If this is not desirable, setting the dependency-check="objects" attribute value specifies that an error should be thrown in this case.
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 668 total points
ID: 35696294

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question