Hi I have the following short code :
https://github.com/shmuel-buchnik/scope-issue
I am getting the following error :
"Invalid property 'targetBeanName' of bean class [C]: Bean property 'targetBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"
I will be happy to understand way .
Thanks in advance.
Adding context file to save access to 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>
Well after debugging this is the issue :
When you define a parent in spring that means that you want to inherit parent bean configuration.
When you define scope proxy the proxy bean holds two properties targetBeanName and ProxyTargetClass.
When you inherit a bean that is a scoped proxy you get those properties as part of merging parent bean configuration .Then your bean try to find a setter for setting property and raise exception.
This means that in our example even if c was not scoped proxy we were still get the exception.