简体   繁体   English

根和子应用程序上下文中具有相同名称的Bean?

[英]Bean with same name in Root and Child Application Context?

If I create bean with same name in Root Application context and Child Application context 如果我在根应用程序上下文和子应用程序上下文中创建具有相同名称的bean
( as in Root Application Context and dispatcher servlet context ) 如在根应用程序上下文和调度程序servlet上下文中
will child application context override the bean definition ? 子应用程序上下文会覆盖bean定义吗?
What will be the behavior please explain ? 请问这是什么行为?
Also explain what will be the behavior In Java Config if I include other Configuration Class and both contain bean with same name. 如果我包含其他配置类并且都包含具有相同名称的bean,还请解释Java Config中的行为。
Will two beans be created ? 是否会创建两个bean? Or one will override the other. 否则一个将覆盖另一个。

As per my Experimentation 根据我的实验

In the parent and child Application Context new Bean is created for each Application Context irrespective whether Bean name is same or not . 在父级和子级Application Context中, 无论Bean名称是否相同 ,都会为每个Application Context创建一个新Bean。

Any call made from ( autowired by ) parent application context refers to Bean in Parent Application Context . 父应用程序上下文进行的任何调用(由其自动装配) 是指父应用程序上下文中的Bean
Any call made from ( autowired by ) child application context refers to Bean in Child Application Context . 从( 子程序自动) 子应用程序上下文进行的任何调用都在子应用程序上下文中引用Bean

And In Java Config importing other configuration which contains bean with same name does not create a new Bean and Bean Definition is Overridden. 并且在Java Config中,导入包含同名bean的其他配置不会创建新Bean,并且Bean Definition被覆盖。 This effect is same as Importing bean of same name from XML. 此效果与从XML导入相同名称的bean相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM