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.