随笔 - 6  文章 - 129  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 822231
  • 排名 - 49

最新评论

阅读排行榜

评论排行榜

一个关于struts + spring + hibernate整合事务配置的问题(请教高手)
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager" ref="transactionManager"></property>
  <property name="transactionAttributes">
   <props>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 
 <bean id="userDAO" class="dgut.ke.dao.impl.UserDAO">
      <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
<bean id="userService"  parent="txProxyTemplate"  class="dgut.ke.service.impl.UserService">
    <property name="userDAO" ref="userDAO" />
</bean>
... ....
启动Tomecat时出了错.之前没有添加事务处理时.上面的代码是可以正常运行的.添加事务之后却出现以下错误
ERROR - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
解决办法

<bean id="userService"  parent="txProxyTemplate"  class="dgut.ke.service.impl.UserService">
    <property name="userDAO" ref="userDAO" />
</bean>
换成以下代码就可以正常运行了
 <bean id="userService" parent="txProxyTemplate">
      <property name="target">
           <bean class="dgut.ke.service.impl.UserService">
                <property name="userDAO" ref="userDAO"></property>
           </bean>
      </property>
 </bean>

请教一下为什么会出现这种情况?
哪位高手解释下,谢谢!!!

posted on 2007-10-07 13:36 Ke 阅读(2781) 评论(1)  编辑  收藏 所属分类: exception问题区

FeedBack:
# re: struts + spring + hibernate整合事务配置的问题(请教高手)[未登录] 2007-11-30 09:03 hehe
一样的问题,在此找到答案,谢了
曾试着这样
<bean id="userService" parent="txProxyTemplate">
<property name="target">
<bean class="dgut.ke.service.impl.UserService">
</bean>
</property>
</bean>
就是没想到要把DAO作为属性加进去
  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: