我编写的日志机制不起作用。我使用:
aspectjrt 1.7.3 方面jweaver 1.7.3 Spring 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)")
这意味着没有记录任何内容。
最佳答案
您确定您的注释不在 mypackage2
中与 TimeLogger
相同吗?
您还可以尝试使用:
@Around("execution(* *(..)) && @annotation(ann)")
public Object around(ProceedingJoinPoint point, TimeLog ann) throws Throwable {
...
}
关于java - @annotation 周围的方面不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34754410/