2

AspectJでアノテーション@Beforeを使用してメソッドから戻ることはできますか。

@Before
public void simpleAdvice(JoinPoin joinPoint) {
    if (smth == null)
    /* return for method, which annotated */
}

私の質問が十分でない場合は、詳細について別の人に質問してください。

4

2 に答える 2

0
@Aspect
@SuppressAjWarnings({ "adviceDidNotMatch" })
public class TestAspect {
    @Around("execution(@Monitor void *..*.* ())")
    public void aroundMethodWithMonitorAnnotation(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.err.println("Around - before a()");

        String sessionId = (String) proceedingJoinPoint.getArgs()[0];

        if(sessionId != null){
            proceedingJoinPoint.proceed();
            System.err.println("Around - after a()");
        } else {
            System.err.println("Around - a() not called");
        }
    }

    public static void main(String[] args) {
        new TestAspect().a();
    }

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.METHOD })
    public @interface Monitor {
    }

    @Monitor
    public void a() {
        System.err.println("a()");
    }
}
于 2013-09-16T07:06:55.313 に答える