0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Bean登録アノテーションについてを調べよう!

Posted at

Bean登録アノテーション

  • Component
    • Spring MVCに限らず、SpringのDIコンテナにbeanとして登録したいクラスへ付与する。
    • タグと同じ役割
  • Repository
    • パーシステンスレイヤー、永続性を持つ属性(ファイル、データベース)を持つクラス
    • Spring MVCでデータ層のクラス(DAO等のDBアクセスを行うクラス)に付与する
  • Service
    • Sping MVCでサービス層のクラス(ビジネスロジック等)に付与する
    • Service は業務処理を提供する
    • サービスレイヤー、ビジネスロジックを持つクラス
  • Controller
    • Spring MVCでコントローラー層のクラスに付与する。
    • プレゼンテーションレイヤー、フェブアプリケーションでフェブリクエストとレスポンスの処理を行うクラス

Bean依存関係の挿入アノテーション

  • Autowired
    • 精密な依存関係の挿入が必要な場合有用
    • Autowiredはプロパティ、setterメソッド、コンストラクタ、一般メソッドに適用可能
    • 依存しているオブジェクトを挿入するときに主にTypeを利用
    • @Autowiredは「property、contructor-arg」タグと同じ役割
  • Resource
    • アプリケーションで必要つする資源を自動連動するとき利用
    • Resourceはプロパティ、setterメソッドに適用可能
    • 依存しているオブジェクトを挿入するときは主にNameを利用
  • Value
    • 単純に値を挿入するときに使用
    • @Value("Spring")は「property .. value="Spring" /」と同じ役割
  • Qualifier
    • Qualifierは@Autowiredと一緒に使う
    • Autowiredはタイプでスキャンして挿入するため、同じタイプのBeanオブジェクトがいくつか存在している場合、特定のBeanをスキャンするため使用
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?