拥有一个带有 Facade 层、Service 层和 Dao 层的 RESTful Web 服务。试图记录类的所有方法的所有调用,用注释@Log标记
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {
}
这是方面代码:
public class LoggingAspect {
@Around("@target(Log)")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
log.debug("Start " + pjp.getSignature().getName());
Object result = pjp.proceed();
log.debug("End " + pjp.getSignature().getName());
return result;
}
}
Facade、Service 和 Dao 用@Log 标记。一些例子:
public Obj Facade.createObj(String name){ //1
return service.createObj(name);
}
public Obj Service.createObj(String name){ //2
return dao.createObj(name);
}
public Obj Dao.createObj(String name){ //3
Long idOfCreatedObj = /*code that creates an object and returns it's ID*/;
return loadObjById(idOfCreatedObj); /* load the created object by id */
}
public Obj Dao.loadObjById(Long id){ //4
return /* code that loads the object by it's id */;
}
在此示例中,方法 1、2、3 已成功记录。但是没有记录嵌套的 dao 方法 (loadObjById)。
为什么?
PS在spring-config.xml中有
<aop:aspectj-autoproxy proxy-target-class="true"/>