-4

可能重复:
@Transactional 和 AOP 之间的混淆

我是 Spring 框架的新手,我在 @Transactional 和 tx:advice 之间感到困惑,因为我读到 AOP 用于提供声明性事务管理,而 @Transactional 也有同样的作用......它们是一样的吗?@Transactional 在内部使用 AOP 吗?在哪里使用 AOP 以及在哪里使用 @Transactional

4

2 回答 2

0

在过去几年从事的所有项目中,@Transactonal 是一个更实用的解决方案。然而,在一些非常特殊的情况下,我还必须使用 Spring AOP 来允许使用多个 JDBC 连接/TransactionManager,因为@Transaction 与单个事务管理器相关联。

于 2013-01-01T17:16:26.850 回答
0

@Transactional只是一种简单的方法来声明一个类的方法或所有方法(如果放在类级别)是事务性的。

Spring 使用 AOP 代理来拦截对方法的调用,启动事务(如果需要),在方法执行后,它会提交或回滚事务。

参考:http ://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-decl-explained

于 2013-01-01T19:58:48.363 回答