<spring Combat >4: Spring for facets

Source: Internet
Author: User

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

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.