Junior — Middle
Can it be considered that beans have a predefined scope level by default?
sobes.tech AI
Answer from AI
Yes, Spring Framework beans have a default scope — singleton. This means that by default, Spring creates one instance of the bean for the entire application context, and this instance is used everywhere the bean is injected.
If no other scope is explicitly specified (for example, prototype, request, session), then the bean will be singleton.
Example:
@Component
public class MyService {
// default singleton
}
If you want the bean to be recreated on each request, you can specify:
@Component
@Scope("prototype")
public class MyService {
// new instance on each request
}
Thus, singleton is the default scope for beans in Spring.