본문 바로가기

Spring Boot

@Configuration + @Bean vs @Component

728x90

결론

외부 라이브러리를 사용해야 할 때는 우리가 직접 @Component를 그 라이브러리에 선언할 수 없으므로, @Configuration + @Bean 조합으로 스프링 빈을 생성하고, 그 외에 우리가 직접 제어할 수 있는 클래스들은 @Component를 붙임으로써 자동으로 스프링 빈으로 등록되도록 하자.

 

 

참고하면 좋은 글:  [Spring] 빈 등록을 위한 어노테이션 @Bean, @Configuration, @Component 차이 및 비교 - (1/2) - MangKyu's Diary (tistory.com)


[참고자료]

https://stackoverflow.com/questions/67691575/when-should-you-use-configuration-instead-of-service-controller-component-fo

 

When should you use @Configuration instead of @Service/@Controller/@Component for defining beans

I am trying to understand the Spring Framework better and my question is basically: What is the benefit of the @Configuration annotation compared to @Service/@Controller/@Repository (or @Component ...

stackoverflow.com

https://stackoverflow.com/questions/10604298/spring-component-versus-bean

 

Spring: @Component versus @Bean

I understand that @Component annotation was introduced in spring 2.5 in order to get rid of xml bean definition by using classpath scanning. @Bean was introduced in spring 3.0 and can be used with @

stackoverflow.com

 

728x90
반응형