- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是来自 Spring documentation ,第 9.5.4 节
<bean id="myAdvisor" class="com.mycompany.MyAdvisor">
<property name="someProperty" value="Custom string property value"/>
</bean>
<bean id="debugInterceptor"class="org.springframework.aop.interceptor.DebugInterceptor">
</bean>
<bean id="person"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces" value="com.mycompany.Person"/>
<property name="target" ref="personTarget"/>
<property name="interceptorNames">
<list>
<value>myAdvisor</value>
<value>debugInterceptor</value>
</list>
</property>
</bean>
现在,代码下面的注释显示:
You might be wondering why the list doesn't hold bean references. The reason for this is that if the ProxyFactoryBean's singleton property is set to false, it must be able to return independent proxy instances. If any of the advisors is itself a prototype, an independent instance would need to be returned, so it's necessary to be able to obtain an instance of the prototype from the factory; holding a reference isn't sufficient.
有人可以解释一下这是如何工作的吗?我知道各种范围。所以我知道如果顾问是原型(prototype),则需要返回一个新实例。但我没有得到最后一句话(以粗体突出显示)。如果我指定 ref="debugInterceptor"
bean 创建机制会改变吗?这是否意味着如果我ref
一个bean,它将是一个单例实例。
最佳答案
Does it mean that if I ref a bean, it will be a singleton instance.
否,但是当引用的 bean 被实例化时,被引用的 bean 也会被实例化。如果 Bean A(单例范围)有 Bean B(原型(prototype)范围)的ref
,那么 Bean B 将被创建并注入(inject)到 Bean A 中一次。就 Bean A 而言,Bean B 是一个单例。
ProxyFactoryBean
必须保存一个 Bean 名称列表,以便在创建 ProxyFactoryBean
本身时不会强制取消对拦截器的引用。通过保存名称列表,它可以将拦截器的查找推迟到最后一刻,从而允许拦截器成为原型(prototype)作用域的 bean。
这有帮助吗?
关于java - Spring 在 ProxyFactoryBean 中使用 ref 引用原型(prototype) bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7991855/
我正在尝试使用 MethodInterceptor 和 ProxyFactorBean 来生成特定方法的审核信息。 我可以看到bean拦截OpMethod已初始化,但当调用originalOp时它永远
我正在尝试实现 ProxyFactoryBean 以创建 AOP 代理,但遇到了一些错误。谁能告诉我哪里出错了。 代码和异常轨迹trace如下: 表演者.java public interfa
我在 ProxyFactoryBean 中遇到问题类, 我们想要获取 targetBean 的类名的 ProxyFactoryBean . 当我们调用 getType 时在 BeanFactory给
我有以下定义: myInterceptor 我定义了 2 个类:MyInterceptor 和 MyCl
在我的应用程序中,我最初使用 ProxyFactoryBean 将事务应用到我的 DAO Bean,如下所示; com.tradi
我一直被这个问题困扰。 使用的组件:Spring 1.2.8、Hibernate 3.2.0 cr1、tomcat、struts、java 6 我正在尝试从 ProxyFactoryBean 获取 b
这是来自 Spring documentation ,第 9.5.4 节 myAdvisor
我是一名优秀的程序员,十分优秀!