This commit is contained in:
2021-11-14 13:01:38 +08:00
parent 0382f8ad01
commit c99bad22cb
4 changed files with 35 additions and 1 deletions

View File

@@ -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"

View File

@@ -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 {
}

View File

@@ -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;
}
}

View File

@@ -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() {