@annotation周围的方面不起作用



我编写了不起作用的日志记录机制。我使用:

aspectjrt 1.7.3aspectjweaver 1.7.3弹簧3.0.6

@Aspect
public class TimeLogger {
    private static final Logger LOG = Logger.getLogger(TimeLogger.class);
    //@Around("execution(* myMethod(..))")
    //@Around("execution(* *(..)) && @annotation(TimeLog)")
    @Around("execution(* *(..)) && @annotation(mypackage.TimeLog)")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Method method = MethodSignature.class.cast(point.getSignature()).getMethod();
        long start = System.currentTimeMillis();
        Object result = point.proceed();
        LOG.info("AAAAAAAAAAAAA");
        return result;
    }
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TimeLog {
    LogLevels logLevel() default LogLevels.DEBUG;
}

<bean id="execTimeLogger" class="mypackage2.TimeLogger">
</bean>

问题是这记录了一些

  //@Around("execution(* myMethod(..))")

但这不起作用:

 //@Around(" execution(* *(..)) && @annotation(mypackage.TimeLog)")

这意味着没有任何记录。

您确定您的注释与TimeLogger不在mypackage2中吗?

你也可以尝试使用:

@Around("execution(* *(..)) && @annotation(ann)")
public Object around(ProceedingJoinPoint point, TimeLog ann) throws Throwable {
    ...
}

最新更新