Spring (iv): Faceted programming AOP

Source: Internet
Author: User

    • Crosscutting concerns: Features that are distributed across multiple applications

    • Faceted programming AOP: Separating crosscutting concerns from business logic


When you use aspect-oriented programming, you still define common functionality in one place, but you can declaratively define how the feature will be applied, without modifying the affected classes.

Crosscutting concerns can be modularized into special classes, which are called facets.

Benefits :

    • Focus each focus on one place rather than spreading it across multiple codes

    • The service modules are more concise because they contain only the code for the main focus, and the secondary concerns are shifted to the slices.


1. Define AOP Terminology1.1. Notice (Advice)

The work of the facets is called notification.

Notifications define what facets are and when to use them.


There are 5 types of notifications that spring facets can apply to:

    • before--call Notification before the method is called

    • after--calls the notification after the method completes, regardless of whether the method execution succeeds.

    • after-returning--calls the notification after the method executes successfully.

    • after-throwing--invokes the notification after the method throws an exception.

    • The around--notification wraps the method that is notified, before the method call is notified and after the call executes the custom behavior.

1.2, Connection point (Joinpoint)

A connection point is a point at which a slice can be inserted during the execution of an application, when the method is called, when an exception is thrown, or even when a field is modified.

1.3. Tangent point (Pointcut)

Tangency helps reduce the range of connection points that are notified by the tangent, and the definition of the pointcut matches one or more connection points to be woven into the notification. These pointcuts are typically specified with explicit class names and method names, or they are specified using regular expressions that define matching classes and method names.

1.4. Slice (Aspect)

Facets are the combination of notifications and pointcuts, which together define the entire contents of a slice-what it is, when and where it functions.

1.5. Introduction (Introduction)

Introduction allows us to add a new method or property to an existing class.

1.6. Weave in (Weaving)

Weaving is the process of applying facets to a target object to create a new proxy object.

There are multiple points in the life cycle of the target object that can be woven into:

    • Compile-time-slices are woven into the target class when it is compiled. This approach requires a special compiler. AspectJ's weaving compiler is the way in which the facets are woven in this manner.

    • Class load period-facets are woven into the target class when it is loaded into the JVM.

    • Run time-facets are woven at some point in the application's run. In general, when you weave a slice, the AOP container dynamically creates a proxy object for the target object, which is how Spring AOP weaves the tangent.


2. Spring Support for AOP

Todo


Spring (iv): Faceted programming AOP

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.