Spring2.5与DWR使用中遇到的事务问题

 在SSH中添加事务,代码如下:

<bean id="transactionIntercepter" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
        <props>
        <prop key="cim*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames">
        <list>
            <value>addproService</value>
            <value>queryproServise</value>
            <value>examservice</value>
            <value>measureService</value>
        </list>
    </property>
    <property name="interceptorNames">
        <list>
            <value>transactionIntercepter</value>
        </list>
    </property>
</bea

其中 measureSrvice 要用到事务。

MeasureService的配置如下:

<?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.5.xsd">
    <!-- dao -->
    <bean id="measureDao" class="com.chengxin.measure.dao.impl.MeasureDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- service -->
    <bean id="measureService" class="com.chengxin.measure.service.impl.MeasureServiceImpl">
        <property name="dao" ref="measureDao" />
    </bean>
    <!-- action -->
    <bean id="measureAction" class="com.chengxin.measure.action.MeasureAction" scope="prototype">
        <property name="service" ref="measureService"></property>
        <property name="typeService" ref="typeservice"></property>      
    </bean>
</beans

 DWR相关measure配置如下 :

<create creator="spring" javascript="measure">
    <param name="beanName" value="measureService"></param>
    <include method="checkPunish" />
    <include method="checkNotify" />
    <include method="exists" />
</create>

 此时,页面上执行JavaScript脚本代码:measure.exists时总是弹出“ERROR”提示框。

网上百度下,在DWR配置中加上错误信息提示:

<convert converter="spring" match="java.lang.StackTraceElement" />
<convert converter="exception" match="java.lang.Exception" />

 再次执行,提示“Object is not an instance of declaring class"。

再次百度,大意是measureService由代理生成,DWR调用的时候与声明的类不匹配,所以出错。要修改Spring-bean的配置文件,修改如下:

<?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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <!-- dao -->
    <bean id="measureDao" class="com.chengxin.measure.dao.impl.MeasureDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- service -->
    <bean id="measureService" class="com.chengxin.measure.service.impl.MeasureServiceImpl">
        <aop:scoped-proxy/>
        <property name="dao" ref="measureDao" />
    </bean>
    <!-- action -->
    <bean id="measureAction" class="com.chengxin.measure.action.MeasureAction" scope="prototype">
        <property name="service" ref="measureService"></property>
        <property name="typeService" ref="typeservice"></property>      
    </bean>
</beans>

 再次执行,OK。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值