【问题标题】:property 'configurationClass' is not writable or has an invalid setter method. Does the parameter type of the setter属性“configurationClass”不可写或设置方法无效。是否setter的参数类型
【发布时间】:2013-06-11 22:02:13
【问题描述】:
<?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 的参数类型是否与 getter 的返回类型匹配?请帮我解决这个问题

【问题讨论】:

  • 你有什么版本的 JBoss AS?
  • @Pavel Horal 我正在使用 jBoss7 请为此建议我任何解决方案

标签: spring hibernate maven


【解决方案1】:

您的 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" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2015-08-10
    • 2013-01-31
    • 2018-09-26
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2015-09-07
    相关资源
    最近更新 更多