Announcement Announcement Module
No announcement yet.
Unable to set property with multiple signatures Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to set property with multiple signatures

    I have a concrete class which extends abstract one. The abstract class defines a property:
    public void setConfiguration(CoreSettings)
    and the concrete class defines another similar property:
    public void setConfiguration(TransactionalSettings)
    The two interfaces, CoreSettings and TransactionalSettings are unrelated so one cannot be cast to the other. The relevant part from my Spring configuration is:

    <bean id="coreSettings" class="org.zimowski.azdao.CoreSettingsImpl">
    	<property name="IBatisSettings" ref="iBatisSettings"/>
    	<property name="sortProperties" ref="sortProps"/>
    	<property name="sqlMapClientProxy" ref="sqlMapClientProxy"/>
    	<property name="nativePagingEnabled" value="true"/>
    	<property name="raiseCriticalExceptions" value="false"/>
    	<property name="raiseTolerableExceptions" value="false"/>
    	<property name="forceStatementNamespaces" value="false"/>
    	<property name="daoSuffix" value="DaoSqlMap"/>
    <bean id="transactionalSettings" 
    	<property name="transactionExecutor" ref="transactionExecutor"/>
    <!-- =========== DAOs ================ -->
    <bean id="baseDao" abstract="true">
    	<property name="configuration" ref="coreSettings"/>
    <!-- transaction support WITHOUT sequences -->
    <bean id="baseTransactionalDao" abstract="true" parent="baseDao">
    	<property name="configuration" ref="transactionalSettings"/> 
    <bean id="userDao" parent="baseTransactionalDao" 
    	<property name="configuration">
    		<bean parent="coreSettings">
    			<property name="operations">
    					<entry key="get:long" value="getUserById"/>
    					<entry key="get:string" value="getUserByLogin"/>
    Basically I have a generic template for core settings which most DAOs use, so I inject it into a base all DAOs derive from. Then I inject TransactionalSettings into still abstract transactional DAO definition. At the concrete level (specific daos) I'm overriding core settings with settings specific to each DAO. This is where I'm running into a problem. After injecting CoreSettings (for the 2nd time) into concrete class, Spring says that property is invalid, as it insists the argument should be TransactionalSettings:

    2008-02-22 11:07:31,640 [initWebApplicationContext] ERROR org.springframework.web.context.ContextLoader(6) ( - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [org/zimowski/album/data/config/album-data-ibatis.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
    PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.zimowski.azdao.CoreSettingsImpl] to required type [org.zimowski.azdao.TransactionalSettings] for property 'configuration'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.zimowski.azdao.CoreSettingsImpl] to required type [org.zimowski.azdao.TransactionalSettings] for property 'configuration': no matching editors or conversion strategy found
    Is there a special configuration I need to use to tell Spring which version of method I'm trying to set? I was under the impression that Spring would take care of this automagically by type of argument.


  • #2
    This is by Spring design. Whenever you inject a property xyz (say reference to a bean of type XYZ) into a bean, Spring will looking for a setter 'void setXyz(Whatever we)' and make a single effort to cast passed in 'XYZ' type to 'Whatever' type. In your case, of course, Spring whines.

    OK, workaround, if you can, simple use a property name other than 'configuration' in your TransactionalDao class..