Spring-autowire Mechanism

Source: Internet
Author: User

In the xml configuration file, there are five types of autowire, which can be specified using the autowire attribute in the <bean/> element.

 

  • Description
  • No does not use automatic assembly. You must use the ref element to specify the dependency. The default value is set.
  • Byname is automatically assembled Based on the attribute name. This option will check the container and find
  • Automatically assemble the bean with the same attributes.
  • Bytype if the container contains a bean of the same type as the specified property
  • This attribute is automatically assembled. If multiple beans of this type exist, an exception is thrown.
  • And indicates that the bytype method cannot be used for automatic assembly.
  • To the matched bean, nothing happens. You can also set
  • Dependency-check ="Objects"Let spring throw an exception.
  • The constructor and bytype methods are similar, except that they are applied to the constructor parameters. For example
  • If no bean of the same type as the constructor parameter is found in the container
  • Exception.
  • Autodetect determines whether to use
  • Constructor or bytype for automatic assembly. If the default
  • Constructor. bytype is used.
  • you can set bean to invalidate automatic assembly.
    when bean is configured in XML format, set the autowire-candidate attribute of the element to false, in this way, the container will not consider the bean when looking for an automatic assembly object, that is, it will not be considered as a candidate for automatic assembly of other beans, however, the bean itself can still use automatic assembly to inject other beans.

    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.