Skip to content

PropertyPathFactoryBean requires a bean setter in version 3.1.0.RELEASE. It didn't in 3.0.6.RELEASE [SPR-8949] #13589

Closed
@spring-projects-issues

Description

@spring-projects-issues

David Boden opened SPR-8949 and commented

The org.springframework.beans.factory.config.PropertyPathFactoryBean class seems to have got more strict in 3.1.0.RELEASE. I have an object with an "options" field and a "getOptions()" method but no corresponsing "setOptions()" method. Fair enough, it isn't a bean :)

However, I just wanted to log the fact that the behaviour has recently changed and maybe to help someone else out who's seeing the same error.

A reasonable workaround is to switch to the MethodInvokingFactoryBean and specify "getOptions" as the method name. Unfortunatly, this isn't quite as elegant as I would hope because I have 2 levels of beans to navigate. The original spring config was:

<bean id="applicationIdFromCommandLine"
    class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
    <property name="targetObject" ref="core.commandLineProcessor" />
    <property name="propertyPath" value="options.applicationId" />
</bean>

Note the "options.applicationId" meaning "the applicationId property inside the options bean". I've got it working by using:

<bean id="applicationIdFromCommandLine"
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetObject" ref="core.commandLineProcessor" />
            <property name="targetMethod" value="getOptions" />
        </bean>
    </property>
    <property name="targetMethod" value="getApplicationId" />
</bean>

Could someone in the know please make a judgement about whether it's appropriate to relax the demand for the setter? If we want to keep it strict then fine, I'll move everything over to MethodInvokingFactoryBean.

Stack trace:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'core.CommandLineOptions': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'options' of bean class [com.fxcash.fxcore.application.impl.option.CoreCommandLineArgumentProcessorImpl]: Bean property 'options' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:109)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 48 more
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'options' of bean class [com.fxcash.fxcore.application.impl.option.CoreCommandLineArgumentProcessorImpl]: Bean property 'options' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:729)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:721)
at org.springframework.beans.factory.config.PropertyPathFactoryBean.getObject(PropertyPathFactoryBean.java:208)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 53 more


Issue Links:

1 votes, 2 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions