【问题标题】:Combination of scope-proxy and parent范围代理和父级的组合
【发布时间】:2016-04-17 13:41:35
【问题描述】:

您好,我有以下短代码:

https://github.com/shmuel-buchnik/scope-issue

我收到以下错误:

“bean类[C]的无效属性'targetBeanName':bean属性'targetBeanName'不可写或有无效的setter方法。setter的参数类型是否与getter的返回类型匹配?”

我会很高兴理解方式。

提前致谢。

添加上下文文件以保存对 github 的访问

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
   xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<bean name="a" class="A">
 <property name="action" ref="c"/>
    </bean>
<bean name="b" class="B" scope="prototype">
    <property name="d" ref="d"/>
    <aop:scoped-proxy proxy-target-class="false"/>
 </bean>
<bean name="c" class="C" parent="b" scope="prototype">
    <aop:scoped-proxy proxy-target-class="false"/>
</bean>
<bean name="d" class="D"/>


</beans>

【问题讨论】:

    标签: spring dependency-injection spring-ioc spring-io


    【解决方案1】:

    调试之后就是这个问题了:

    当你在 spring 中定义一个 parent 时,意味着你想要继承 parent bean 的配置。

    当您定义范围代理时,代理 bean 拥有两个属性 targetBeanName 和 ProxyTargetClass。

    当您继承一个作为作用域代理的 bean 时,您将这些属性作为合并父 bean 配置的一部分。然后您的 bean 尝试找到一个设置器来设置属性并引发异常。

    这意味着在我们的示例中,即使 c 不是作用域代理,我们仍然会遇到异常。

    【讨论】:

      【解决方案2】:

      如果 bean 定义配置为 &lt;aop:scoped-proxy&gt;,则您不能将 bean 定义用作

      因此,只需删除 b bean 的 &lt;aop:scoped-proxy&gt; 声明即可。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-31
        • 2011-07-03
        • 1970-01-01
        • 2014-02-08
        • 2019-10-30
        • 1970-01-01
        • 2016-11-17
        • 1970-01-01
        相关资源
        最近更新 更多