如何从方面读取接口变量

时间:2019-04-21 07:46:58

标签: java interface aspect

我的界面:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogMethod {
    boolean isEnabled() default false;
}

我的长相:

@Aspect
@Component
public class LogMethodAspect {

    @Pointcut("@within(com.middleware.internal.aspect.LogMethod) || @annotation(com.middleware.internal.aspect.LogMethod)")
    public void loggingPointcut() {
    }

    @Before("loggingPointcut()")
    public Object logBefore(final JoinPoint joinPoint) throws Throwable {
        //...
        return null;
    }
}

有什么方法可以读取logBefore方法中的inEnabled值吗?

1 个答案:

答案 0 :(得分:0)

this的答案可能与您的答案有关。简而言之,它读取联接点的签名以检索带注释的方法和方法参数,并检索添加到目标类中给定方法和参数的注释数组。