属性'configurationClass'不可写或具有无效的setter方法。是setter的参数类型

时间:2013-06-15 09:50:05

标签: spring hibernate maven

<?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:util="http://www.springframework.org/schema/util"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/util
            http://www.springframework.org/schema/util/spring-util-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee 
            http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

        <util:properties id="hibernateProperties" location="classpath:hibernate.properties" />

        <bean id="usermanagementSessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="usermanagementDataSource" />
            <property name="configLocation" value="classpath:hibernate.cfg.xml" />
            <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
            <property name="hibernateProperties" ref="hibernateProperties" />
        </bean>

        <jee:jndi-lookup id="usermanagementDataSource" jndi-name="java:jboss/datasources/usermanagementDS" />

        <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
            init-method="init" destroy-method="close">
            <property name="forceShutdown" value="false" />
            <property name ="startupTransactionService" value="true"/>
        </bean>

        <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
            <property name="transactionTimeout" value="30" />
        </bean>

        <bean id="transactionManager"
            class="org.springframework.transaction.jta.JtaTransactionManager">
            <property name="transactionManager" ref="atomikosTransactionManager" />
            <property name="userTransaction" ref="atomikosUserTransaction" />
        </bean>

        <bean id="User" class="com.ecom.data.access.model.User"/>
        <bean id="myFactory" class="com.ecom.data.access.dao.MyFactory"/>

    </beans>

我正在使用hibernate 4 spring 3 maven 3,我有这个configuratiobn文件,在这里我使用本地会话工厂,它正确编译,但它给出了错误 当我使用JBoss服务器部署它时,服务器控制台会给出错误'configurationClass'不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配?请帮我解决这个问题

1 个答案:

答案 0 :(得分:13)

您的bean定义表明您正在尝试配置Hibernate 3,而不是Hibernate 4.您可能已经关注了不正确的示例或教程。在Hibernate 4中没有configurationClass属性。只需删除它:

<bean id="usermanagementSessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="usermanagementDataSource" />
    <property name="configLocation" value="classpath:hibernate.cfg.xml" />
    <property name="hibernateProperties" ref="hibernateProperties" />
</bean>

使用Hibernate 4,您也不需要提供配置XML。您所能做的就是指定要扫描@Entity类的包:

    <property name="packagesToScan" value="com.ecom.data.access.model" />