Last active
July 29, 2023 04:58
-
-
Save thanoojgithub/d52991abe097e6a215b3b1d024a0e58c to your computer and use it in GitHub Desktop.
Spring Boot Notes 1.0v
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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.