springboot-aop笔记

1.pom.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <modelVersion>4.0.0</modelVersion>
 6 
 7     <groupId>com.xncoding</groupId>
 8     <artifactId>springboot-aop</artifactId>
 9     <version>1.0.0-SNAPSHOT</version>
10     <packaging>jar</packaging>
11 
12     <name>springboot-aop</name>
13     <description>SpringBoot AOP演示</description>
14 
15     <parent>
16         <groupId>org.springframework.boot</groupId>
17         <artifactId>spring-boot-starter-parent</artifactId>
18         <version>2.0.4.RELEASE</version>
19     </parent>
20 
21     <properties>
22         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24         <java.version>1.8</java.version>
25     </properties>
26 
27     <dependencies>
28         <dependency>
29             <groupId>org.springframework.boot</groupId>
30             <artifactId>spring-boot-starter-web</artifactId>
31             <exclusions>
32                 <exclusion>
33                     <groupId>org.springframework.boot</groupId>
34                     <artifactId>spring-boot-starter-tomcat</artifactId>
35                 </exclusion>
36             </exclusions>
37         </dependency>
38         <dependency>
39             <groupId>org.springframework.boot</groupId>
40             <artifactId>spring-boot-starter-jetty</artifactId>
41         </dependency>
42         <dependency>
43             <groupId>org.springframework.boot</groupId>
44             <artifactId>spring-boot-starter-aop</artifactId>
45         </dependency>
46     </dependencies>
47 
48     <build>
49         <plugins>
50             <plugin>
51                 <groupId>org.apache.maven.plugins</groupId>
52                 <artifactId>maven-compiler-plugin</artifactId>
53                 <version>3.6.1</version>
54                 <configuration>
55                     <source>1.8</source>
56                     <target>1.8</target>
57                 </configuration>
58             </plugin>
59             <plugin>
60                 <groupId>org.apache.maven.plugins</groupId>
61                 <artifactId>maven-surefire-plugin</artifactId>
62                 <version>2.20</version>
63                 <configuration>
64                     <skip>true</skip>
65                 </configuration>
66             </plugin>
67             <plugin>
68                 <groupId>org.springframework.boot</groupId>
69                 <artifactId>spring-boot-maven-plugin</artifactId>
70                 <executions>
71                 </executions>
72             </plugin>
73         </plugins>
74     </build>
75 
76 </project>
View Code

 

2.CommandLineRunner、ApplicationRunner 接口

 接口被用作将其加入spring容器中时执行其run方法。多个CommandLineRunner可以被同时执行在同一个spring上下文中并且执行顺序是以order注解的参数顺序一致。

使用注解

@Component
@Order(1)

 

3.相关注解

@Component
@Aspect

@Pointcut(value = "@annotation(com.xncoding.aop.aspect.UserAccess)")

 @Before("access()")

@Around("@annotation(userAccess)")

 

@Around("webLog()")

@Before("webLog()")

@After("webLog()")

@AfterReturning(returning = "ret", pointcut = "webLog()")

 @AfterThrowing("webLog()")

 

posted @ 2019-06-07 21:28  缘来就是你  阅读(107)  评论(0)    收藏  举报