永发信息网

Error creating bean with name 'txManager' defined in class path resource [beans.xml]

答案:2  悬赏:20  手机版
解决时间 2021-03-20 20:03
  • 提问者网友:無理詩人
  • 2021-03-19 22:28
错误信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManager' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

----------------------------------------------------------
beans.xml配置如下:
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="username" value="aa"></property>
<property name="password" value="xxxxxxx"></property>
<property name="initialSize" value="1"></property>
<property name="maxActive" value="500"></property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>cn/ssh/beans/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update

</value>
</property>
</bean>

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>

<bean id="serviceBean" class="cn.ssh.services.impl.ServiceImpl"></bean>
</beans>
运行出错,求高手解答
最佳答案
  • 五星知识达人网友:低血压的长颈鹿
  • 2021-03-19 22:48
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

应该是不能加上这:
<property name="sessionFactory" ref="sessionFactory"></property>

我觉得可以改成
<property name="dataSource" ref="dataSource"></property>
试试。。。
全部回答
  • 1楼网友:渡鹤影
  • 2021-03-19 23:48
这个两个怎么没有ref配置? 应该是这两个property的配置没有成功找不到proxytargetclass或者transactionattributes他 我没这么干过。不知道这两个是你自己的 还是配置中就有的 你自己再修改下吧
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯