我是 Spring AOP 的新手,并按照baeldung文章尝试了以下代码。方面类:@Aspect@Componentpublic class LoggingAspect { private final static Logger LOGGER = LoggerFactory.getLogger(LoggingAspect.class); @Around("@annotation(Debug)") public Object beforeDebug(ProceedingJoinPoint debugJoinpoint) { LOGGER.debug("----------------Debug message logged from {}", debugJoinpoint.getSignature().toString()); System.out.println("IN HERE"); long start = System.currentTimeMillis(); Object proceed = null; try { proceed = debugJoinpoint.proceed(); } catch (Throwable e) { e.printStackTrace(); } long executionTime = System.currentTimeMillis() - start; System.out.println(debugJoinpoint.getSignature() + " executed in " + executionTime + "ms"); return proceed; }}注解:@Retention(RUNTIME)@Target(METHOD)@Loggable(type = "debug")public @interface Debug {}用于测试的演示类:@SpringBootApplication@Componentpublic class Application { public static void main(String[] args) throws InterruptedException { SpringApplication.run(Application.class, args); dumb(); } @Debug public static void dumb() throws InterruptedException { Thread.sleep(2000); }}有人可以指出我在上面做错了什么吗?该建议不会执行,而且我在这里和那里谷歌搜索后无法解决这个问题,不知道我错过了什么。
添加回答
举报
0/150
提交
取消