【spring】spring aop

Aspect-Oriented Programming (AOP)

First, the official introduction

Another consideration by providing a program structure of the embodiment, aspect-oriented programming (AOP) supplemented with object-oriented programming (OOP). The key unit is modular in OOP class, the modular unit is in terms of the AOP. Supporting modular concerns, such as transaction management across multiple types and objects. (AOP in the literature, this is commonly referred to concerns crosscutting concerns.)

 

Second, notes

#### EnableAspectJAutoProxy enabled by default 

#### CGLIB to achieve AOP time, you need to configure spring.aop.proxy-target-class = true, otherwise the default using the standard Java implementation

#### @Before: In execution before running the point of attachment method. We can use the recommended type @Before comments marked as Before.

#### @After: After the completion of the implementation of the connection point method (either normal or raise an exception) the implementation of recommendations. We can create post informed use @After comment.

#### @AfterReturning: Sometimes we wish to recommend that method is only executed if the connection point method normally. We can mark methods recommended @AfterReturning comment after return.

#### @AfterThrowing: This is recommended only when exceptional execution method throws at the connection point, we can use it declaratively roll back the transaction. For such advice, we use @AfterThrowing comment.

#### @Around: This is the most important and most powerful recommendations. The proposal revolves around the connection point method, we can also choose whether to perform a connection point method. We can prepare recommendations code before and after the execution junction method of execution. It is recommended that the return value of responsibility is to call around the connection point method and return some value in this method. We use @Around annotation method to create around the proposed


#### execution priority content @Order (1) in @Before, and then execute @Order (2) the contents of
#### takes precedence in the @After and @AfterReturning @Order (2) contents, and then perform content @Order (1) of




GitHub: https://github.com/Baker-abc/baker-learning-springboot

Guess you like

Origin www.cnblogs.com/kbian/p/12014605.html