Spring AOP practices and Spring AOP practices

Source: Internet
Author: User

Spring AOP practices and Spring AOP practices

Spring AOP and AspectJ are two different implementations of AOP. The former is a dynamic proxy, and the latter is a static proxy.

The role of AOP is to separate concerns. It separates business-independent logic and encapsulates it into modules to decouple core businesses from general logic.

First, there are several concepts to understand:

  • Aspect (aspect): A simple understanding. It splits public logic and encapsulates it into modules. This module is aspect, which can be understood as a function. For example, a transaction is a function.
  • Joinpoint: in Spring AOP, the connection point is a method.
  • Advice (notification): action taken at a specific connection point
  • Pointcut
  • Target object: The method actually called.

To facilitate understanding, we think like this: aspect is the function we want to implement, so the thing we need to do with this function is advice, where these functions are applied is pointcut.

In Spring AOP, defining an AOP function takes only three steps:

1. Declare aspect

2. Define joinpoint

3. Define advice

 

The following example uses two methods to implement an AOP Function

The project structure is as follows:

The dependent jar is as follows:

 

Method 1: annotation Based on @ AspectJ

Method 2: XML-based configuration file

 

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.