def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);                tstatus = transactionManager.getTransaction(def); 我如果使用spring的platformtransaction接口来处理事务。是不是每个server类中都要加入上述代码啊,有没有简洁点的写法呢?

解决方案 »

  1.   

    用AOP思想 在spring的配置文件里 注入事物管理 用文件来自动管理事物
      

  2.   

    我也想配置 annotation 来处理事务。可惜我配置applicationContext中datasource时出了一个问题,没配置成功。
    因为我用的jboss数据源。配置时总是提示第一个bean id not bound错误。加上<use-java-context> false也不行。
      

  3.   

    没用spring之前我用ThreadLocal写了一个TransactionManager,对connection的工厂类实现静态代理,从而实现了transaction的管理,那叫一个累,还不能像EJB那样实现跨域的事务。
      

  4.   


    我就是在配置文件中引入事务管理内容时出错啊。我jndi用的是jboss的数据源,
      

  5.   

    用AOP思想 在spring的配置文件里 注入事物管理 用文件来自动管理事物<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"
         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.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"><!-- Ttransaction Manage -->
    <bean id="transationManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <!-- txAdvice 你要拦截的方法名称 -->
    <tx:advice id="txAdice" transaction-manager="transationManager">
    <tx:attributes>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="del*" propagation="REQUIRED"/>
    <tx:method name="update*" propagation="REQUIRED"/>
    <tx:method name="*" propagation="SUPPORTS" read-only="true"/>
    </tx:attributes>
    </tx:advice>
    <!-- Config -->
    <aop:config>
    <aop:pointcut id="bizMethods" expression="execution(* org.standard.hr.biz.impl.*.*(..))"/>
    <aop:advisor advice-ref="txAdice" pointcut-ref="bizMethods"/>
    </aop:config>
    </beans>
    //execution(* org.standard.hr.biz.impl.*.*(..))" 拦截org.standard.hr.biz.impl下面的所有类、所有方法、(..)所有变量
      

  6.   

    谁给我一个spring、中配置外部jndi例子,我配置的那个总是报not bound 错误