我的界面:

@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值?

最佳答案

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

08-25 08:07