我正在为我的应用程序实现某种监控框架。基本思想是使用 Aspectj 编写一段代码,通过 JMX 公开带有某些注释的变量。 所以我使用切入点
@Around("get (@mypackage.Gauge * *) && @annotation(annotation)")
但是,为了通过 JMX 公开我的变量,我需要获取它的值一次(以便发生 JMX 绑定(bind))。我使用编译时编织。有什么方法可以在加载带有 @Gauge 注释的类后执行特定的代码吗?
最佳答案
Is there any way that i can execute a certain piece of code once the class with
@Gauge
annotation is loaded?
是的。试试这个:
after() : staticinitialization(@Gauge *) {
// Do something here
}
关于java - Aspectj 围绕字段和类初始化的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501701/