java - org.springframework.beans.NotWritablePropertyException

标签 java spring hibernate spring-mvc liferay

我尝试使用LocalSessionFactory运行一个spring项目,我得到一个空指针,因为我必须初始化类加载器。不管怎样,我最后得到了这个异常!

由以下原因引起:org.springframework.beans.NotWritablePropertyException:bean 类 [org.springframework.orm.hibernate3.LocalSessionFactoryBean] 的属性“sessionFactoryClassLoader”无效:Bean 属性“sessionFactoryClassLoader”不可写或具有无效的 setter 方法。

setter 的参数类型与 getter 的返回类型是否匹配?

有什么建议吗?

这里是实现:

<?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:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 <!-- Data Source Declaration -->
 <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/Database" />
        <property name="username" value="postgres" />
        <property name="password" value="password" />

 </bean>


 <!-- Session Factory Declaration -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="DataSource"></property>
        <property name="mappingLocations">
            <list>
                <value>classpath:META-INF/products.xml
                </value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
            </props>
        </property>
        <property name="sessionFactoryClassLoader" ref="portletClassLoader" />
    </bean>

 <!-- Enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

 <!-- Transaction Manager is defined -->
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
        <bean id="portletClassLoader" class="com.liferay.portal.kernel.portlet.PortletClassLoaderUtil" factory-method="getClassLoader" />
    </beans>

顺便说一句,我想使用 springFramework 或 hibernate 库将 com.liferay.portal.kernel.portlet.PortletClassLoaderUtil 替换为另一个类加载器!

最佳答案

sessionFactoryClassLoader 不是 org.springframework.orm.hibernate3.LocalSessionFactoryBean 的属性。 它可用于扩展 SessionFactoryImpl 的 PortletSessionFactory 实现。 .

关于java - org.springframework.beans.NotWritablePropertyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23917676/

相关文章:

java - Hibernate SQL 查询仅比较时间戳字段中的日期

java - 如何使用 ToStringBuilder 排除单个变量

java - 按值降序对 linkedhashmap 进行排序

java - Spring 使用 @ResponseBody 返回修改后的 JSONObject

java - 代表多个用户使用 OAuth2RestTemplate

java - 如何自检Spring bean作用域?

java - 使用 EntityManager 更新 Hibernate

java - 我无法让我的 printf 语句在 java 中对齐

java - 如何在 Firestore 中批量写入后获取更新的文档引用?

java - Kotlin - 调用 getter 时未加载 HibernateProxy