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?

【更新中】Springのアノテーション

Posted at

Configuration

概要

JavaConfigクラスを作成します。
@Configuration を付けることにより、SpringはJavaConfigクラスと認識し、記載したコンフィグレーションを読み込んでくれます。

サンプル

@Configuration
public class FooConfig {
    ...
}

ステレオタイプアノテーション

概要

Beanとして管理してほしい具象クラスにつけるアノテーションです。
@Component, @Service, @Repository, @Controller などが該当します。
そのクラスに特定の 役割(stereotype) を与えるためのアノテーションです。

サンプル

@Service // ビジネスロジック(サービス層)
public class FooService {
    ...
}

Bean

概要

Beanとして管理してほしいオブジェクトを返す メソッド につけるアノテーションです。
JavaConfigクラスの中(つまり @Configuration がついているクラス)のメソッドを定義します。

サンプル

@Configuration
public class FooConfig {
    @Bean
    public FooService fooService() {
        return new FooService(); // 管理してほしいオブジェクトを返す
    }
}
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?