围绕@annotation的方面不起作用

时间:2016-01-12 21:50:17

标签: java spring aspectj

我写的日志机制不起作用。我用:

aspectjrt 1.7.3 aspectjweaver 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)")

这意味着没有记录任何内容。

1 个答案:

答案 0 :(得分:0)

您确定,您的注释不在mypackage2TimeLogger相同吗?

您还可以尝试使用:

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