我尝试使用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/