Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.beans.NotWritablePropertyException: Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.beans.NotWritablePropertyException:

    Hi guys,

    I got the following error while doing junit testing:


    [junit] Null Test: Caused an ERROR
    [junit] null
    [junit] java.lang.ExceptionInInitializerError
    [junit] at java.lang.Class.forName0(Native Method)
    [junit] at java.lang.Class.forName(Unknown Source)
    [junit] Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'manager' defined in file [D:\Workspace\stufftolet\src\service\com\stufftolet \service\applicationContext-service.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManager' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'transactionManager' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1031)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:823)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:345)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
    [junit] at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
    [junit] at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:269)
    [junit] at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:318)
    [junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:81)
    [junit] at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
    [junit] at com.borneo.service.BaseServiceTestCase.<clinit>(Ba seServiceTestCase.java:34)
    [junit] ... 5 more
    [junit] Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManager' of bean class [org.springframework.aop.framework.ProxyFactoryBean]: Bean property 'transactionManager' is not writable or has an invalid setter method: Does the parameter type of the setter match the return type of the getter?
    [junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:831)
    [junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:733)
    [junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:890)
    [junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:917)
    [junit] at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:906)
    [junit] at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1022)
    [junit] ... 14 more


    My applicationContext-resources.xml

    <beans>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>classpath:mail.properties</value>
    <value>classpath:database.properties</value>
    </list>
    </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="${hibernate.connection.driver_class}"/>
    <property name="url" value="${hibernate.connection.url}"/>
    <property name="username" value="${hibernate.connection.username}"/>
    <property name="password" value="${hibernate.connection.password}"/>
    </bean>
    </beans>


    My applicationContext-hibernate.xml


    <beans>
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
    <property name="mappingResources">
    <list>
    <value>com/borneo/model/users/Person.hbm.xml</value>
    <value>com/borneo/model/users/UserCookie.hbm.xml</value>
    <value>com/borneo/model/users/UserFavourite.hbm.xml</value>
    <value>com/borneo/model/users/SuspendedUser.hbm.xml</value>
    <value>com/borneo/model/users/SuspendType.hbm.xml</value>

    <value>com/borneo/model/posting/Category.hbm.xml</value>
    <value>com/borneo/model/posting/PostingDetails.hbm.xml</value>
    <value>com/borneo/model/posting/CategorizedItem.hbm.xml</value>


    </list>
    </property>

    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">@HIBERNATE-DIALECT@</prop>
    <prop key="hibernate.show_sql">false</prop>

    </props>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Generic DAO - can be used when doing standard CRUD -->
    <bean id="dao" class="com.borneo.dao.hibernate.BaseDAOHibernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- LookupDAO: Hibernate implementation -->
    <bean id="lookupDAO" class="com.borneo.dao.hibernate.LookupDAOHibernate ">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- UserDAO: Hibernate implementation -->
    <bean id="userDAO" class="com.borneo.dao.hibernate.UserDAOHibernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- RoleDAO: Hibernate implementation -->
    <bean id="roleDAO" class="com.borneo.dao.hibernate.RoleDAOHibernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>


    <!-- Geographical DAO Definition: Hibernate implementation -->
    <bean id="geographicalDAO" class="com.borneo.dao.hibernate.GeographicalDAOHib ernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <!-- Category DAO Definition: Hibernate implementation -->
    <bean id="categoryDAO" class="com.borneo.dao.hibernate.CategoryDAOHiberna te">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>



    </beans>



    My applicationContext-service.xml

    <beans>
    <bean id="lookupManager" class="com.borneo.service.impl.LookupManagerImpl">
    <property name="lookupDAO"><ref bean="lookupDAO"/></property>
    </bean>

    <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <!-- Generic manager that can be used to do basic CRUD operations on any objects -->
    <bean id="manager" parent="txProxyTemplate">
    <property name="target">
    <bean class="com.borneo.service.impl.BaseManager">
    <property name="DAO"><ref bean="dao"/></property>
    </bean>
    </property>
    </bean>

    <!-- Transaction declarations for business services. To apply a generic transaction proxy to
    all managers, you might look into using the BeanNameAutoProxyCreator -->
    <bean id="userManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="com.borneo.service.impl.UserManagerImpl">
    <property name="userDAO"><ref bean="userDAO"/></property>
    </bean>
    </property>
    <!-- Override default transaction attributes b/c of LoginCookie methods -->
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED,-UserExistsException</prop>
    <prop key="activate*">PROPAGATION_REQUIRED,-ActivateCodeNotExistException</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="*LoginCookie">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    <property name="preInterceptors">
    <list>
    <ref bean="userSecurityInterceptor"/>
    </list>
    </property>
    </bean>

    <bean id="mailEngine" class="com.borneo.service.MailEngine">
    <property name="mailSender"><ref bean="mailSender"/></property>
    <property name="velocityEngine"><ref bean="velocityEngine"/></property>
    </bean>

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailS enderImpl">
    <property name="host"><value>${mail.host}</value></property>
    <property name="username"><value>${mail.username}</value></property>
    <property name="password"><value>${mail.password}</value></property>
    </bean>

    <!-- Configure Velocity for sending e-mail -->
    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEng ineFactoryBean">
    <property name="velocityProperties">
    <props>
    <prop key="resource.loader">class</prop>
    <prop key="class.resource.loader.class">
    org.apache.velocity.runtime.resource.loader.Classp athResourceLoader
    </prop>
    <prop key="velocimacro.library"></prop>
    </props>
    </property>
    </bean>

    <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage" singleton="false">
    <property name="from"><value>${mail.default.from}</value></property>
    </bean>

    <!-- Add new Managers here -->

    <bean id="categoryManager" parent="txProxyTemplate">
    <property name="target">
    <bean class="com.borneo.service.impl.CategoryManagerImpl ">
    <property name="categoryDAO"><ref bean="categoryDAO"/></property>
    </bean>
    </property>
    </bean>

    </beans>


    and my CategoryServiceTest.java


    public class CategoryServiceTest extends BaseServiceTestCase {

    private CategoryManager mgr = null;
    private Log log = LogFactory.getLog(CategoryManagerTest.class);
    private Category cat;


    protected void setUp() throws Exception {
    mgr = (CategoryManager) ctx.getBean("categoryManager");
    }

    protected void tearDown() {
    mgr = null;
    }

    public void testGetUser() throws Exception {
    cat = (Category) mgr.getCategory(new Long(8709));

    if (log.isDebugEnabled())
    log.debug(cat.getId());

    }

    public static void main(String[] args) {
    junit.textui.TestRunner.run(UserManagerTest.class) ;
    }
    }


    the BaseServiceTestCase.java:


    public class BaseServiceTestCase extends TestCase {

    private static Log log = LogFactory.getLog(BaseManagerTestCase.class);
    protected static ResourceBundle rb = null;
    protected static ApplicationContext ctx = null;

    static {
    ResourceBundle db = ResourceBundle.getBundle("database");
    String daoType = db.getString("dao.type");
    String[] paths = {"classpath*:/**/service/applicationContext-service.xml",
    "classpath*:/**/dao/applicationContext-resources.xml",
    "classpath*:META-INF/applicationContext-hibernate.xml"};
    ctx = new ClassPathXmlApplicationContext(paths);
    }


    public BaseServiceTestCase() {
    String className = this.getClass().getName();

    try {
    rb = ResourceBundle.getBundle(className);
    } catch (MissingResourceException mre) {
    log.warn("No resource bundle found for: " + className);
    }
    }

    protected Object populate(Object obj) throws Exception {

    Map map = ConvertUtil.convertBundleToMap(rb);

    BeanUtils.copyProperties(obj, map);

    return obj;
    }
    }



    Please help, TIA !

    regards,
    Mark[/b]

  • #2
    [edit 14/Oct] Oops. I had, genuinely, meant to put the answer in too but got distracted hunting the essay URL. Apologies :oops:

    Mark,

    What have you so far done to try and track this down yourself?

    Please see: http://www.catb.org/~esr/faqs/smart-questions.html

    Kind regards,

    Comment


    • #3
      Hi David,

      I have google it a lot of time but still can't find any solution !

      Mark

      Comment


      • #4
        Mark,

        You are (accidentally, I guess) using ProxyFactoryBean instead of TransactionProxyFactory bean. Only the latter has a 'transactionManager' property...

        Comment


        • #5
          Hi Colin,

          Thanks a lot for your help, it's working now ! It's my stupid mistake !

          best regards,
          Mark

          Comment


          • #6
            Hi,

            Could you please help somebody for this issue?

            I am getting the following exception when I run the TestCases using Maven. Actually we have migrated from

            Spring 2.5.4 to Spring 3.0.6
            hibernate 3.1.3 to Hibernate 3.6.6.

            Exception Log:
            16976 [main] ERROR org.springframework.test.context.TestContextManage r - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener@4cbcaf] to prepare test instance [com.mastercard.eps.mpg.common.dao.hibernate.Activa tionCodeDAOTest@183698f]
            java.lang.IllegalStateException: Failed to load ApplicationContext
            at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:308)
            at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.injectDependencies (DependencyInjectionTestExecutionListener.java:109 )
            at org.springframework.test.context.support.Dependenc yInjectionTestExecutionListener.prepareTestInstanc e(DependencyInjectionTestExecutionListener.java:75 )
            at org.springframework.test.context.TestContextManage r.prepareTestInstance(TestContextManager.java:321)
            at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.createTest(SpringJUnit4ClassRunner.j ava:211)
            at org.springframework.test.context.junit4.SpringJUni t4ClassRunner$1.runReflectiveCall(SpringJUnit4Clas sRunner.java:287)
            at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
            at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.methodBlock(SpringJUnit4ClassRunner. java:289)
            at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:50)
            at org.junit.runners.ParentRunner$3.run(ParentRunner. java:193)
            at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:52)
            at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:191)
            at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:42)
            at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:184)
            at org.junit.internal.runners.statements.RunBefores.e valuate(RunBefores.java:28)
            at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
            at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:70)
            at org.junit.runners.ParentRunner.run(ParentRunner.ja va:236)
            at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
            at org.apache.maven.surefire.junit4.JUnit4TestSet.exe cute(JUnit4TestSet.java:62)
            at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.executeTestSet(AbstractDirectoryTestSuite .java:140)
            at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.execute(AbstractDirectoryTestSuite.java:1 27)
            at org.apache.maven.surefire.Surefire.run(Surefire.ja va:177)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.maven.surefire.booter.SurefireBooter.ru nSuitesInProcess(SurefireBooter.java:345)
            at org.apache.maven.surefire.booter.SurefireBooter.ma in(SurefireBooter.java:1009)
            Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.transaction.interceptor.Trans actionInterceptor#0': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManagerBeanName' of bean class [org.springframework.transaction.interceptor.Transa ctionInterceptor]: Bean property 'transactionManagerBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1361)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1086)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 93)
            at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
            at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:290 )
            at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:192)
            at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
            at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
            at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
            at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:84)
            at org.springframework.test.context.support.AbstractG enericContextLoader.loadContext(AbstractGenericCon textLoader.java:1)
            at org.springframework.test.context.TestContext.loadA pplicationContext(TestContext.java:280)
            at org.springframework.test.context.TestContext.getAp plicationContext(TestContext.java:304)
            ... 29 more
            Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'transactionManagerBeanName' of bean class [org.springframework.transaction.interceptor.Transa ctionInterceptor]: Bean property 'transactionManagerBeanName' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:1052)
            at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:921)
            at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:7 6)
            at org.springframework.beans.AbstractPropertyAccessor .setPropertyValues(AbstractPropertyAccessor.java:5 8)
            at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1358)
            ... 43 more

            configuration:
            ------------------
            spring-transaction.xml
            <!-- Turn on annotation based transactions -->
            <tx:annotation-driven />

            <bean id="transactionManager"
            class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
            </bean>

            spring-xxx-tests.xml
            -----------------------
            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
            <property name="url" value="jdbc:oracle:thin:@//xxx:yyy/zzzz"/>
            <property name="username" value="xxxx" />
            <property name="password" value="yyyy" />
            <property name="defaultTransactionIsolation" value="2"/>
            </bean>

            <bean id="systemDAO"
            class="com.test.common.dao.hibernate.impl.TestSyst emDAOImpl">
            <property name="sessionFactory" ref="sessionFactory" />
            <property name="databasePropertyPlaceholderConfigurer" ref="databasePropertyPlaceholderConfigurer"/>
            </bean>

            <!-- Beans listed here don't override but are specific to tests. -->
            <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
            <property name="dataSource" ref="dataSource" />
            </bean>

            Comment


            • #7
              This is definitely a problem with incompatible jar versions. Check if you have changed all the spring jar versions to the latest (i.e. spring-orm)

              Comment


              • #8
                Caused by: org.springframework.beans.NotWritablePropertyExcep tion: Invalid property

                Hi Amila,

                I am using same version for spring-orm also. Please find the mapping from pom.xml

                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                </dependency>
                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                </dependency>
                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                </dependency>
                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                </dependency>
                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                </dependency>
                <!-- <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-hibernate3</artifactId>
                <version>2.0.8</version>
                </dependency> -->
                <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>3.0.6.RELEASE</version>
                </dependency>

                do we need to really configure the "org.springframework.transaction.interceptor.Trans actionProxyFactoryBean" or Are above configurations are fine?

                Thanks,
                Chaatna

                Comment

                Working...
                X