6.

【Spring】@Componentアノテーションとは

編集

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

@Componentとは

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

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

@Component
public class TestComponent {

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

}
 

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. @After
  2. @Autowired
  3. @Bean
  4. @Before
  5. @Column
  6. @Component
  7. @Configuration
  8. @Controller
  9. @Data
  10. @Entity
  11. @GeneratedValue
  12. @Id
  13. @Modifying
  14. @PathVariable
  15. @PropertySource
  16. @Repository
  17. @RequestBody
  18. @RequestMapping
  19. @ResponseBody
  20. @RestController
  21. @Service
  22. @SpringBootApplication
  23. @Table
  24. @Transactional
  25. @Value