What's the default scope of Spring's @Component
annotation?
If you don't define a scope at all, is it application scoped? The Spring documentation does not say anything about default scope.
@Component is an annotation that allows Spring to automatically detect our custom beans. In other words, without having to write any explicit code, Spring will: Scan our application for classes annotated with @Component. Instantiate them and inject any specified dependencies into them.
Spring's default scope is singleton.
Yes, that is correct, @Component is a Spring bean and a Singleton. About singletons - spring beans are all in singleton scope by default. The only thing you have to have in mind is that you should not store state in field variables (they should only hold dependencies).
The main difference between these annotations is that @ComponentScan scans for Spring components while @EnableAutoConfiguration is used for auto-configuring beans present in the classpath in Spring Boot applications.
The singleton scope is the default scope in Spring.
This is said here
And also in the current doc you find
singleton (Default) Scopes a single bean definition to a single object instance per Spring IoC container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With