STS in AOP implementation

1. Add aop dependency in pom.xml:

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2. Create the connection point (Jointed pointed)

Spring boot connection point (jointed pointed) is a function, it is usually a function of a service class identifier top with @Service; only requirement is that this class must be implemented by an interface, and the point must be a function interface .

3. Create a section (Aspect)

Aspect is a class, which consists @Aspect identified, and then, which contains several functions @Before, @Around, @ After, @ AfterReturn, @ AfterThrowing identified function for weaving point of attachment; for simplicity this class needs increasing a tangent point (@Pointcut function) function is used to identify the point of attachment, with a regular expression which denotes the fully qualified string concatenation function of the point;

4. Create a controller can be tested.

As can be seen, this section does not control the operation of the connection points, it is only to complete some transaction related to the work function of the point of attachment, such as a connection point for a call before the database connection, after the completion of the storage connection should be closed in the event of after the abnormal need to display exception information.

Guess you like

Origin www.cnblogs.com/myboat/p/11486390.html