この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:3
ページ更新者:guest
更新日時:2018-05-10 05:45:07

タイトル: @Before

本稿はSpringFrameworkの@Beforeについて説明します。

@Beforeとは

@Beforeはメソッド単位で付与するアノテーションです。

@Beforeは@Acpectが付与されたクラス内で使用されます。

@Beforeが付与されたクラスは、execution内の条件に当てはまる場合、対象の処理の実行前に@Beforeメソッドが実行されます。

※AOPに関してはこちらを参照。

以下、@Beforeを使用したサンプルです。

@Aspect
@Component
public class TestAOP {

    @Before("execution(* com.example.springmvc2.*.*(..))")
    public void before(JoinPoint joinPoint) {
        System.out.println("Method Start:"  + joinPoint.getSignature());
    }

    @After("execution(* com.example.springmvc2.*.*(..))")
    public void after(JoinPoint joinPoint) {
        System.out.println("Method End:"  + joinPoint.getSignature());
    }
}