【发布时间】:2019-01-07 14:19:51
【问题描述】:
我正在阅读 spring 文档核心容器我想了解注入协作者时 ref parent 的目的然后我发现了父上下文子上下文或父容器和当前容器的概念这是部分我对此感到困惑: This part of doc
通过 parent 属性指定目标 bean 创建一个 对当前父容器中的 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 父级的目的是什么 提前谢谢你
【问题讨论】:
标签: java spring spring-mvc