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

@Componentとは

@Component付与したクラスはSpirngのコンポーネントとして認識され、ApplicationContextに登録されることで、DI対象のクラスとなります。(@Autowiredで指定できるようになる)

以下、@Componentの簡単なサンプルです。

@Component
public class TestComponent {

    public void componentMethod() {
        System.out.println("This is Component!");
    }

}