6
<?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 的返回类型匹配?请帮我解决这个问题

4

1 回答 1

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" />
于 2013-06-15T12:27:21.633 回答