AspectJでアノテーション@Beforeを使用してメソッドから戻ることはできますか。
@Before
public void simpleAdvice(JoinPoin joinPoint) {
if (smth == null)
/* return for method, which annotated */
}
私の質問が十分でない場合は、詳細について別の人に質問してください。
@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()");
}
}