Spring TX:建议和Spring AOP切入点之间的区别
我是新来的春天,具有hibernate的工作知识。我的工作是通过使用Spring声明式方法来实现交易。由于Google的帮助,我成功地在Google的帮助下完成了交易。但是无法清楚地了解我在application-
context.xml中使用的术语。
1。
<tx-advice> </tx-advice>
1. <aop-config>
// here is point cut were declared
</aop-config>
有人可以向我解释以上几点,与此同时,我也试图从google上了解它。
回答:
您已经成功实施了spring transaction,
在Spring我们可以通过三种方式实现交易:
您实现的被称为 。
简而言之,您transaction通过Spring的AOP功能进行了实现。
将tx:advice XML配置与基于XML的AOP配置耦合在一起,可以实现协同组合。例如,我们可以使用方法名称来自动确定我们要对该方法应用哪种事务。
我们想在与启动所有方法应用事务save和modify如savePizza(),saveColdDrink(),modifyOrder(),modifyBill()。对于这些,我们必须advice在xml文件中定义:
<tx:advice id="txAdvice" > <tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
正如我们在上面一行中所说的那样,我们的建议已经准备就绪,我们只希望以save或开头的方法进行交易modify。现在,我们将使用的pointcut元素来说明哪些bean需要上述建议aop-
config。例如,假设我们要将交易建议应用于com.mytransaction.service包内所有可用的类。
为此,我们必须在xml文件中添加以下行:
<aop:config> <aop:pointcut id="allServices"
expression="execution(*com.mytransaction.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServices"/>
</aop:config>
简而言之,<tx:advice>是指我们要应用的交易方式或行为。 pointcut内部元素<aop-
config>表示要在何处应用交易,例如<aop:advisor advice-ref="txAdvice" pointcut-
ref="allServices"/>
以上是 Spring TX:建议和Spring AOP切入点之间的区别 的全部内容, 来源链接: utcz.com/qa/411303.html

