add aop
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
"repo": {
|
||||
"dependencies": [
|
||||
"me.hatter:commons:3.0",
|
||||
"org.springframework.boot:spring-boot-starter-web:2.3.12.RELEASE"
|
||||
"org.springframework.boot:spring-boot-starter-web:2.3.12.RELEASE",
|
||||
"org.springframework.boot:spring-boot-starter-aop:2.3.12.RELEASE"
|
||||
],
|
||||
"testDependencies": [
|
||||
"junit:junit:4.12"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package me.hatter.sample.common.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Traceable {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.hatter.sample.common.aspect;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class TraceableAspect {
|
||||
|
||||
@Around("@annotation(me.hatter.sample.common.annotation.Traceable)")
|
||||
public Object trace(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
System.out.println("[TraceableAspect] " + joinPoint);
|
||||
Object result = joinPoint.proceed();
|
||||
System.out.println("[TraceableAspect] " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package me.hatter.sample.web.controller;
|
||||
import me.hatter.sample.common.CustomConfiguration;
|
||||
import me.hatter.sample.common.annotation.Permission;
|
||||
import me.hatter.sample.common.annotation.SystemTime;
|
||||
import me.hatter.sample.common.annotation.Traceable;
|
||||
import me.hatter.sample.common.session.CustomSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -40,6 +41,7 @@ public class SampleController {
|
||||
return "Hello: " + id;
|
||||
}
|
||||
|
||||
@Traceable
|
||||
@Permission
|
||||
@GetMapping("/custom-object")
|
||||
public String customObject() {
|
||||
|
||||
Reference in New Issue
Block a user