第二个注释方面未被调用

Second annotated aspect not being called

我正在努力了解 Spring AOP,目前正面临这个问题,TrackedSubTask 注释的第二个方面没有被调用,而 Tracked作品。 感谢任何帮助或线索。

这是我的注释 类:

@RestController
public class Demo {
    @Tracked
    @RequestMapping("/")
    public String index() {
        DemoImpl bar = new DemoImpl();
        bar.foo();
        return "Greetings from Spring Boot!";
    }
}

public class DemoImpl{
    @TrackedSubTask
    public void foo() {
        System.out.println("foo");
    }
}

这是我的注释:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Tracked  {
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TrackedSubTask {
}

这是我的方面:

@Aspect
@Component
class MyAspect {
    @Around("@annotation(annotation)")
    public Object first(ProceedingJoinPoint joinPoint, Tracked annotation) throws Throwable {
        Object proceed = joinPoint.proceed();
        return proceed;
    }

    @Around("@annotation(subTaskAnnotation)")
    public Object second(ProceedingJoinPoint joinPoint, TrackedSubTask subTaskAnnotation) throws Throwable {
        Object  proceed = joinPoint.proceed();
        return proceed;
    }
}

正如 M. Deinum 正确指出的那样,DemoImpl 需要由 Spring 管理。