对于"after():staticinitialization(*)"的@AspectJ语法; [英] @AspectJ syntax for "after() : staticinitialization(*)"
本文介绍了对于"after():staticinitialization(*)"的@AspectJ语法;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 pertypewithin 实例化模型实现跟踪方面. 这样,我就可以在每种类型的每个类中使用一个记录器.
I'm trying to implement a tracing aspect using the pertypewithin instantiation model. In this way, I'll be able to use one logger per class per type.
从周围的一些例子中,我们可以找到以下代码来启动记录器:
From some examples arround the we I can find this code to init the logger:
public abstract aspect TraceAspect pertypewithin(com.something.*) {
abstract pointcut traced();
after() : staticinitialization(*) {
logger = Logger.getLogger(getWithinTypeName());
}
before() : traced() {
logger.log(...);
}
//....
}
不幸的是,我无法将其完全转换为@AspectJ语法(这是我无法控制的项目要求),尤其是其中我需要设置记录器,仅执行一次该代码的部分.
unfortunately, I'm not able to fully translate this to the @AspectJ syntax (it's a project requirement outside my control), especially the part in with I need to setup the logger, executing that code only once.
这可能吗?
谢谢
推荐答案
@Aspect("pertypewithin(com.something.*))")
public abstract class TraceAspect {
Logger logger;
@Pointcut
public abstract void traced();
@Pointcut("staticinitialization(*)")
public void staticInit() {
}
@After(value = "staticInit()")
public void initLogger(JoinPoint.StaticPart jps) {
logger = Logger.getLogger(jps.getSignature().getDeclaringTypeName());
}
@Before(value = "traced()")
public void traceThatOne(JoinPoint.StaticPart jps) {
logger.log(jps.getSignature().getName());
}
}
这篇关于对于"after():staticinitialization(*)"的@AspectJ语法;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文