Spring 注解事务支持

来源:互联网 发布:js在数组的末尾加上空 编辑:程序博客网 时间:2024/05/21 07:08

Spring 事务支持

  1. 在spring配置文件中引入<tx:>命名空间

    <beans      xmlns:tx="http://www.springframework.org/schema/tx"     xsi:schemaLocation="        http://www.springframework.org/schema/tx        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
  2. 具有@Transactional 注解的bean自动配置为声明式事务支持

     <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="defaultTransactionManager" proxy-target-class="true" />
  3. @Transactional 注解可以被应用于接口定义和接口方法、类定义和类的 public 方法上。然而,请注意仅仅 @Transactional 注解的出现不足于开启事务行为,它仅仅 是一种元数据,能够被可以识别 @Transactional 注解和上述的配置适当的具有事务行为的beans所使用。上面的例子中,其实正是 <tx:annotation-driven/>元素的出现 开启 了事务行为。

  4. 参考
    http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/transaction.html 
    http://www.cnblogs.com/younggun/p/3193800.html

    0 0