Skip to content

Instantly share code, notes, and snippets.

@thanoojgithub
Last active July 29, 2023 04:58
Show Gist options
  • Save thanoojgithub/d52991abe097e6a215b3b1d024a0e58c to your computer and use it in GitHub Desktop.
Save thanoojgithub/d52991abe097e6a215b3b1d024a0e58c to your computer and use it in GitHub Desktop.
Spring Boot Notes 1.0v
Spring Boot Notes
@Component vs @Bean
The @Bean annotation is a method-level annotation, whereas @Component is a class-level annotation.
The @Component annotation doesn't need to be used with the @Configuration annotation, whereas the @Bean generic annotation has to be used within a class annotated with @Configuration.
If your component doesn't need to communicate with a database or return an HTTP result, you can use the @Service annotation whenever using the @Component annotation is possible.
@thanoojgithub
Copy link
Author

@component vs @bean

The @bean annotation is a method-level annotation, whereas @component is a class-level annotation.

The @component annotation doesn't need to be used with the @configuration annotation, whereas the @Beangeneric annotation has to be used within a class annotated with @configuration.

If your component doesn't need to communicate with a database or return an HTTP result, you can use the @service annotation whenever using the @component annotation is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment