1 What is tangent-oriented programming
1.1 Defining AOP Terminology
Notification (Advice): The work of a slice is called a notification that defines what the facets are and when to use them (before, after, After-returning, After-throwing, Around).
Connection point (Joinpoint): is a point at which a slice can be inserted during application execution, which can be used to insert into the normal process of the application and add new behavior.
Pointcut (Pointcut): the definition of a tangent point matches one or more connection points that the notification is to be woven into.
Facets (Aspect): Facets are a combination of notifications and pointcuts.
Introduction (Introduction): ingestion allows adding a new method or property to an existing class.
Weaving (Weaving): Weaving is the process of applying facets to a target object to create a new proxy object.
1.2 Spring's support for AOP
Spring notifications are written in Java; Spring notifies the object at run time; Spring only supports method connection points.
2 Selecting a connection point using tangent points
AspectJ pointcut indicators supported by Spring AOP:
- Arg ()
- @args ()
- Execution ()
- This ()
- Target ()
- @target ()
- Within ()
- @within ()
- @annotation
Trigger notification when instrument's play () method executes:
Execution (* Com.hundsun.idol.Instrument.play (..))
Configure Pointcuts to match only specific packages:
Execution (* com.hundsun.idol.Instrument.play (..)) && within (com.hundsun.idol.*)
Beans () can specify that only specific beans are matched:
Execution (* com.hundsun.idol.Instrument.play (..)) and Bean (Kenny)
3 declaring slices in XML
<spring Combat >4: Spring for facets