Spring Combat 3-Minimize Spring XML configuration

Source: Internet
Author: User

Automatically assemble bean properties

A total of four automatic assembly types (need to add the Autowire attribute in the bean configuration to specify which type to use)

  • byname-automatically assembles other beans with the same name or ID as the bean's attributes into the corresponding properties of the bean. If there is no bean that matches the name of the property, the property is not assembled. --Actually the bean ID is compared.

  • bytype-automatically assembles other beans with the same type of bean properties into the corresponding properties of the bean. If there is no bean that matches the type of the property, the property is not assembled. Limitations : If spring finds multiple beans whose type matches the type of the property that needs to be automatically assembled, spring does not guess which one is more appropriate, but throws an exception. However, the following parameters are provided to specify which bean to inject. The primary property of the <bean> element. If the value is true, then the bean will be preferred over other candidate beans. The default is true. If you want to exclude some beans as candidates, you can set their Autowire-candidate property to false. They are all ignored as candidate beans.

  • constructor-automatically assembles other beans with the same type as the bean's constructor into the corresponding entry parameters of the Bean constructor.

  • autodetect-first attempts to assemble automatically using constructor, and if it fails, then try to use Bytype for automatic assembly.

Spring Combat 3-Minimize Spring XML configuration

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.