Difference between @Component and @Bean annotation in Spring?

Soma
Javarevisited
Published in
8 min readApr 3, 2023

--

What is difference between @Component and @Bean annotation in Spring?

Hello folks, if you are preparing for Java Developer and Spring Developer interviews then you must prepare for questions like the difference between X and Y like @bean vs @component.

In the past, I have shared with you about the difference between @Contorller and @RestController annotation and @Controller vs @Service @Repository and in this article, we will take a look at another set of popular Spring annotations.

In Spring, both @Component and @Bean annotations are used to register a bean in the Spring container, but they differ in the way they are used which you will find in this article.

By the way, if you are new to Spring Framework and want to learn Spring in-depth and looking for resources then you can also check the following online courses:

  1. Spring Master Class — Beginner to Expert
  2. Spring & Hibernate for Beginners
  3. Learn Spring: The Certification Class
  4. Master Microservices with Spring Boot and Spring Cloud

All of these are top-rated courses to learn Spring framework in depth but if you need free resources you can also check these free Spring framework courses:

--

--

Soma
Javarevisited

Java and React developer, Join Medium (my favorite Java subscription) using my link 👉 https://medium.com/@somasharma_81597/membership