春天tx:建议和春天aop切口之间的区别 [英] Difference between spring tx:advice and spring aop pointcut
问题描述
我对春天很陌生,对冬眠有一定的了解。
我的工作是通过使用spring声明方法来实现事务。并且,我成功地在谷歌的帮助下完成了工作。但无法清楚地了解我在application-context.xml中使用的术语。
1。
< tx-advice>
< / tx-advice>
-
< AOP-配置>
//这里是点分割
< / aop-config>
有人可以解释我的情况,同时
由于您已成功实施 spring transaction
,
在 Spring
中,我们可以通过三种方式实现事务:
- 平台事务管理。 /static.springsource.org/spring/docs/2.0.x/reference/transaction.html#transaction-declarativerel =nofollow noreferrer>声明式交易管理。
- Programmatic 事务管理。
您实现的内容称为通过XML声明式事务管理 。
I简而言之,您在Spring的 transaction rel =nofollow noreferrer > AOP 功能。
将基于XML的AOP配置与 tx:advice XML
配置结合使用用于协同组合。例如,我们可以使用方法名称来自动找出我们想要在该方法上应用哪种交易。
说我们希望对所有以 save
和修改
开头的方法应用交易,例如 savePizza()
, saveColdDrink()
, modifyOrder()
, modifyBill( )
。对于这些我们必须在我们的xml文件中定义 advice
:
$ b
< tx:advice id =txAdvice>
< tx:attributes>
< tx:method name =save *propagation =REQUIRED/>
< tx:method name =modify *propagation =REQUIRED/>
< / tx:属性>
< / tx:advice>
我们的建议已经准备就绪,正如我们通过使用上面的线所表明的那样,我们只希望在从保存
或修改
开始。现在我们要通过使用 aop-config
的 pointcut
元素来说明哪些bean需要上述建议。例如,假设我们希望将交易建议应用于 com.mytransaction.service
包中的所有类。
为此,我们必须在xml文件中添加以下行:
< AOP:配置>
< aop:pointcut id =allServices
expression =execution(* com.mytransaction.service。*。*(..))/>
< / aop:config>
总之,< tx:advice>
意味着要做什么或者我们想要应用哪种交易行为。
pointcut
里面的元素< aop-config>
表示我们想要应用事务的位置,
表示< aop:顾问advice-ref =txAdvicepointcut-ref =allServices/>
I am new to spring, with working knowledge of hibernate. My job was to implement transaction by using spring declarative approach.And successfully i did with the help of Google, thanks to Google. But not able to understand clearly about the terms I used in application-context.xml.
1.
<tx-advice>
</tx-advice>
<aop-config> // here is point cut were declared </aop-config>
can somebody explain me about above point, Meanwhile I am trying to understand it from the google also.
As you already successfully implemented spring transaction
,
In Spring
we can implement transaction in three ways:
- Platform Transaction Management.
- Declarative Transaction Management.
- Programmatic Transaction Management.
What you implemented is called Declarative Transaction Management via XML.
In short you did the implementation of transaction
by Spring's AOP feature.
Coupling the tx:advice XML
configuration with an XML based AOP configuration makes for synergistic combination. For example, we can use method names to automatically figure out what kind of transaction we want to apply on that method.
Say we want to apply the transaction on all that methods which start with save
and modify
such as savePizza()
,saveColdDrink()
,modifyOrder()
,modifyBill()
. For these we have to define the advice
in our xml file:
<tx:advice id="txAdvice" >
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
Our advice is ready, as we said by using above line that we want transactions only on the methods which start with save
or modify
. Now we are going to say which beans require the above advice by using pointcut
element of aop-config
. For example let say we want to apply the transaction advice to all of the classes which are available inside the com.mytransaction.service
package.
For this, we have to add the following line inside our xml file:
<aop:config>
<aop:pointcut id="allServices"
expression="execution(*com.mytransaction.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServices"/>
</aop:config>
In-short, <tx:advice>
mean what to do or which behavior of transaction we want to apply.
pointcut
element inside <aop-config>
says where we want to apply the transaction,
say <aop:advisor advice-ref="txAdvice" pointcut-ref="allServices"/>
这篇关于春天tx:建议和春天aop切口之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!