Itcast video-spring learning notes (@ autowire annotation and automatic assembly)

Source: Internet
Author: User

ThanksItcastFree video released.

 

@ AutowireInjection by type by default

@ Autowired @ qualifier ("persondaoxxx ")In this way, the component is assembled by name.

@ Autowired(Required = true) Must be injected, cannot beNull,IsFalseNo matter what value is injectedNull

 

All of the above are manually assembled.

Automatic Assembly of dependent objects

For automatic assembly, you can understand it. It is not recommended. Example:

<Bean id = "..." Class = "...">

AutowireThe attribute values are as follows:

bytype : assemble by type, which can be based on the attribute type, search for the bean. if multiple roles are found, an exception is thrown. If not found, the attribute value is null .

byname : Name-based assembly, which can be based on the attribute name, find the bean with the same root attribute name in the container, if not found, that is, the attribute value is null .

constructor and bytype method is similar, the difference is that it is applied to the constructor parameters. If the bean with the same type as the constructor parameter is not found in the container, An exception is thrown.

Autodetect: PassBeanClass introspection mechanism to decide to useConstructorOrBytypeMethod for Automatic Assembly. If the default constructor is foundBytypeMethod.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.