autowire byType vs byName

Posted on 2011-05-04
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

    LVL 47

    Assisted Solution

    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

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now