Help us understand the problem. What is going on with this article?

spring framework 簡易勉強メモ(二):AOP

More than 1 year has passed since last update.

spring framework 簡易勉強メモ(二):AOP

本質

  • 散在コードを本質処理から分離

考え方

  • 散在処理を横断的に実装

代表的な応用場面

  • ログ出力
  • セキュリティチェック
  • トランザクション
  • キャシュー
  • モニタリング
  • 例外ハンドリング

ソース例

@Aspect
@Component
public class MethodStartLoggingAspect {
    @Before("execution(* *..*ServiceImpl.*(..))")
    public void startLog(JoinPoint jp) {
        System.out.println("メソッド開始:" + jp.getSignature());
    }
}

Advice実装方法

  • @Before
    • join point 前実施
  • @AfterReturning
    • join point が正常終了後実施
    • 例外スロー時実施しない
  • @AfterThrowing
    • 例外スロー時実施
    • join point が正常終了後実施しない
  • @After
    • 例外スローにかかわらず終了後実施
  • @Around
    • join point の前後で実施

point cut 式

  • join pointを選択する方法
  • 例:"execution(* ..*ServiceImpl.(..))"
  • 指定の方法
    • メソッド指定
    • クラス型指定
    • 名前などその他指定

AOP常用アノテーション

luohao0404
休み時間にIT関連作業を承ります。 メールでご連絡してください。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした