SpringにおけるDIとAOPの基本メモ

基本的な使い方ベースのメモ。選択肢の詳細は参考文献に詳しくあり。

DI

準備
  • ApplicationContext.xml(設定ファイル)
    • 各beanの定義:クラス名、インスタンス名、フィールド値設定、など
利用

AOP

準備(ApplicationContext.xml)
  • Adviseを表現するBean
    • 織り込むAdvise: org.aopalliance.intercept.MethodInterceptorを実装したクラス
  • PointCutを表現するBean
    • 正規表現で指定するPointCutとAdvice指定: org.springframework.aop.support.RegexpMethodPointcutAdvisor
  • Weavingを表現するBean
    • AOP適用対象のインタフェースとBean、そしてPointcutの組み合わせを指定: org.springframework.aop.framework.ProxyFactoryBean
  • AOP適用対象のBean

参考文献

Java・J2EE・オープンソース Spring入門 ~より良いWebアプリケーションの設計と実装

Java・J2EE・オープンソース Spring入門 ~より良いWebアプリケーションの設計と実装