Aspectj:为什么不能应用建议? [英] aspectj: why advice cannot be applied?

查看:88
本文介绍了Aspectj:为什么不能应用建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了非常基本的aspectJ项目.我不知道为什么不能应用建议.

I've created very basic aspectJ project. I have no idea why advice cannot be applied.

注释

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)  
@Target(ElementType.METHOD)  
@Documented  
public @interface Conditional {  
    String value();  
}  

和AspectJ类:

@Aspect
public class AspectE {

    @Around("call(@Conditional * *.*(..)) && @annotation(conditional)" )
    public Object condition(ProceedingJoinPoint joinPoint, Conditional conditional) throws Throwable {

        System.out.println("entry point says hello!");
        return joinPoint.proceed();
    }
}

主要:

public class Main {

    @Conditional("")
    public static void main(String[] args) {
        System.out.println("main good morning");
    }
}

您能告诉我我应该更改为接收这两个消息吗?

Could you please tell me what I should change to receive both messages?

推荐答案

我认为这是因为call(@Conditional * *.*(..))基本上是编织调用方的,在这种情况下,调用方是命令行,因此没有进行编织

I think it is because of the call(@Conditional * *.*(..)) which basically weaves the callers , the caller in this specific case is the command line and so there is no weaving happening.

您可能应该将其更改为执行,这应该可以工作.

You should probably change it to execution instead, that should work.

@Around("execution(@Conditional * *.*(..)) && @annotation(conditional)" )

这篇关于Aspectj:为什么不能应用建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆