The processing mechanism for beans with the same name in Spring

Reposted from  molashaonian 

Small summary:

If component scanning is enabled and the bean names are different, Spring will try to create a bean, even if the bean of this class is already defined in spring-config.xml.

However, if the bean defined in the spring configuration file and the automatically discovered bean have the same name, then spring will not create a new bean during component scanning.

spring.xml and spring-mvc.xml define beans with the same name, the latter overrides the former

If a bean does not have a no-args constructor, at least one constructor must be automatically connected.
If no constructor is automatically connected, then spring will try to create an object using the default no-args constructor.

The scanning mechanism is the same: the discovered beans have the same name, then spring will not create a new bean during component scanning.
 

Guess you like

Origin blog.csdn.net/qq_28411869/article/details/91038694