我正在阅读spring doc核心容器我想了解ref父母当注入合作者时的目的,然后我发现父上下文子上下文或父容器和当前容器的这个概念这是我混淆的部分它: This part of doc春天的父母上下文和子女上下文有什么区别?
通过父属性指定目标的bean创建 参照豆是在当前 容器的父容器中。父属性的值可以与目标bean的id属性或目标bean的名称 属性中的值之一相同,并且目标bean必须位于当前容器的父容器中 一。当您拥有容器层次结构并且想要将父容器中的 现有bean换成代理时,该代理将具有与父bean相同的名称 ,则主要使用此Bean参考变体 。
<!-- in the parent context -->
<bean id="accountService" class="com.foo.SimpleAccountService">
<!-- insert dependencies as required as here -->
</bean>
<!-- in the child (descendant) context -->
<bean id="accountService" <!-- bean name is the same as the parent bean -->
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref parent="accountService"/> <!-- notice how we refer to the parent bean -->
</property>
<!-- insert other configuration and dependencies as required here -->
</bean>
有人可以给我一些帮助,或者这两类型的上下文的例子吗?以及ref父的用途
好像你说的那样解释mvc是一个很好的例子,谢谢 –