在项目Service层 用spring的代理封装了事务
配置后注入到Action进去准备用
发现注入的不是包装过后代理的代理类,变成了普通Sercvice类了测试发现、Service层的事务是封装成功的,并能正确作用。
在Action中,如果不用注入的方式使用,而是利用上下文去把这个封装的事务bean取出来,也能正确使用
不过。。感觉这样相当的挫。。
咋个注入的方式就不行呢。。

解决方案 »

  1.   

    我把代码贴出来:
    //Service层封装的事务
     <bean id="ServicetransactionBase" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true">     <property name="transactionManager">
                <ref local="transactionManager"/>
           </property>
            <property name="transactionAttributes">
                <props> 
                    <prop key="add*">PROPAGATION_REQUIRED</prop>              
                </props>
            </property>     
     </bean>
    <bean id="goodsrServiceimplTarget" parent="ServicetransactionBase" > 
       <property name="target">
           <ref bean="goodsrService"/>
       </property>
    </bean>//Service层的bean
     <bean id="goodsrService" class="cn.cqctlq.lqdc.service.impl.GoodsrServiceImpl" > 
        <property name="goodsrDao" ref="goodsrdaoimplTarget"></property>
        <property name="checkInoutDao" ref="checkinoutdaoimplTarget"></property>
        <property name="positionDao" ref="positiondaoimplTarget"></property>
        <property name="companyDao" ref="companydaoimplTarget"></property>
         <property name="associatecompanyDao" ref="associatecompanydaoimplTarget"></property>
     </bean>//Action层的、注入封装过后的goodsrServiceimplTarget
     <bean id="GoodsrAction"
          class="cn.cqctlq.lqdc.web.action.GoodsrAction">
          <property name="goodsr">
               <ref bean="Goodsr"/>
          </property>
          <property name="goodsrService">
           <ref bean="goodsrServiceimplTarget" />
          </property>    
           <property name="associatecompanyService">
           <ref bean="associatecompanyService" />
          </property>     
    </bean>
      

  2.   

    我目前写的项目  很简单
     第一步   配置bean 
     <!-- 团购的service都放这里 start -->
    <bean id="gpOrderService" class="com.suning.vgs.groupbuy.service.impl.OrderServiceImpl"></bean>
    <bean id="categoryService" class="com.suning.vgs.groupbuy.service.impl.CategoryServiceImpl"></bean>
    <bean id="queryCityService" class="com.suning.vgs.groupbuy.service.impl.QueryCityServiceImpl"></bean>
    <bean id="staticDataUtil" class="com.suning.vgs.groupbuy.util.StaticDataUtil"></bean>
    <bean id="groupBuyIdGeneratorUtil" class="com.suning.vgs.groupbuy.util.GroupBuyIdGeneratorUtil"></bean>第二部 ,自动注入   类似的 
        @Autowired
        GroupBuyCommonUtil      util;    @Autowired
        RedisHandler            redisHandler;第三部 ,直接调用 比如 redisHandler.getGoods 
    很详细了吧  很简单  
      

  3.   

    对了  上面的 既可以是javabean  也可以是接口 的注入    有不懂就在问吧