How Spring AOP is managed based on XML configuration files

Source: Internet
Author: User

1. Configure Bean

<!--define a generic bean instance that will be used as the aspect bean--><bean id= "Fouradvicebean" class= " Org.crazyit.app.aspect.FourAdviceTest "/><!--again defines a normal bean instance that will be--><bean id= as a aspect bean" Secondadvicebean "class=" org.crazyit.app.aspect.SecondAdviceTest "/><bean id=" Hello "class=" Org.crazyit.app.service.impl.HelloImpl "/><bean id=" World "class=" Org.crazyit.app.service.impl.WorldImpl "/ >

2, configure AOP
<aop:config>,
<!--convert Fouradvicebean to tangent bean The new name is: fouradviceaspect Specifies that the plane has a priority of 2--
<aop:aspect id= "Fouradviceaspect" ref= "Fouradvicebean"  order= "2";
<!--define an after enhancement processing, Specify the pointcut expression directly, using the release () method in the slice bean as the enhanced processing method-->
<aop:after pointcut= "Execution (* Org.crazyit.app.service.impl.*.* (..)) "  method= "Release"/>
<!--define a before enhanced processing,  directly specify Pointcut expressions   take the authority () method in the slice bean as an enhanced processing method--
<aop:before pointcut= "Execution (* org.crazyit.app.service.impl.*.* (..))"  method= "authority"/>
<!--define a afterreturning enhanced processing,  directly specify Pointcut expressions   use the log () method in the slice bean as an enhanced processing method-->
<aop: After-returning pointcut= "Execution (* org.crazyit.app.service.impl.*.* (..))"  method= "Log" returning= "RVT"/
<!--define a around enhancement process that directly specifies the Pointcut expression   PROCESSTX () method in the slice bean as an enhanced processing method-->
<aop:around pointcut= " Execution (* org.crazyit.app.service.impl.*.* (..)) " method=" Processtx "/>
</aop:aspect>

<!--The new name of the slice bean that transforms secondadvicebean into a tangent bean is: secondadviceaspect Specifies that the slice has a priority of 1, and that the enhanced processing in that slice is first woven-in
<aop:aspect id= "Secondadviceaspect" ref= "Secondadvicebean" order= "1" >
<!--defines a before enhancement process that must be of type string (determined by the type of MSG parameter in the Authority method declaration)-
<aop:before pointcut= "Execution (* org.crazyit.app.service.impl.*.* (..)) and args (aa) "method=" authority "/>
</aop:aspect>
</aop:config>


3. Another:

  <aop:pointcut.../> elements can be used to define pointcuts, <aop:pointcut id= "xxx_id" expression= "Execution (* org.crazyit.app.service.impl.*.* (..))"/>

If as a <aop:aspect.../> sub-element it is only valid for that slice

<aop:config.../> a child element that can be shared by multiple slices, then

<aop:after pointcut= "Execution (* org.crazyit.app.service.impl.*.* (..))" method= "Release"/>

Can be changed to:

<aop:after pointcut-ref= "xxx_id" method= "release"/>

How Spring AOP is managed based on XML configuration files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.