在Spring Boot项目中可以使用AOP实现自定义注解,从而实现统一、侵入性小的自定义功能。
比如我们实现一个统一打印日志的自定义注解
引入依赖项目结构org.springframework.boot spring-boot-starter-aopcom.google.guava guava18.0 com.alibaba fastjson1.2.54
D:JAVA-RES
├─.idea
│ └─libraries
├─.mvn
│ └─wrapper
├─src
│ ├─main
│ │ ├─java
│ │ │ └─yeye
│ │ │ └─devops
│ │ │ ├─annotation
│ │ │ ├─config
│ │ │ ├─control
│ │ │ ├─model
│ │ │ └─service
│ │ └─resources
│ │ ├─static
│ │ └─templates
│ └─test
│ └─java
│ └─yeye
│ └─devops
└─target
├─classes
│ └─yeye
│ └─devops
│ ├─annotation
│ ├─config
│ ├─control
│ ├─model
│ └─service
├─generated-sources
│ └─annotations
├─generated-test-sources
│ └─test-annotations
└─test-classes
└─yeye
└─devops
PS D:>
定义注解
定义注解的属性:
package yeye.devops.annotation;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@documented
public @interface TraceLog {
String business();
String module();
}



