解决方案 »

  1.   

    奇怪,我这里Controller只会被初始化一次。
    可以使用父上下文:把数据源,DAO放在父上下文,事务的配置,Service放在子上下文,这样就可以实现事务了。
    有时候父上下文是需要的,如用Shiro的时候,Shiro的配置只能用Listener加载,所有在Shiro的Realm里要访问数据库,就需要把数据源和DAO放在父上下文。
    如下事务的配置放在子上下文加载
    <?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"
           xsi:schemaLocation="
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd">
        <!-- Enable Transaction -->
        <tx:annotation-driven transaction-manager="transactionManager"/>
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
    </beans>
      

  2.   


    不行,实现不了。。
    而且,大神你这样做,Controller里面有事务吗?
      

  3.   

    现在 就好奇 我在一楼 贴的方法,做到了 事务在各层中启用,,,就是bean被扫了 多次,这会有影响吗?
      

  4.   

    我不懂 Spring 配置,但我想只要  bean 是 prototype 而不是 singleton 的话,扫多少次应该是没关系的。
      

  5.   

    楼主  我也用到spring 不过时用到spring的 aop
      我也一样  aspectj 死活活调用2次   无解啊
      

  6.   

    测试事务 http://sms.reyo.cn try {
    dr = logService.removeAndupdate(i, "test" + i, 2);
    } catch (Exception e) {
    dr.setContent("事务失败");
    dr.setStatus(false);
    }