Recall & Review
beginner
What does the @Scope annotation do in Spring Boot?
The @Scope annotation defines the lifecycle and visibility of a Spring bean, controlling how many instances of the bean are created and how long they live.
Click to reveal answer
beginner
Name the default scope of a Spring bean when @Scope is not specified.
The default scope is 'singleton', meaning only one instance of the bean is created and shared across the application context.
Click to reveal answer
intermediate
What is the difference between 'singleton' and 'prototype' scopes in Spring?
'Singleton' creates one shared instance per Spring container, while 'prototype' creates a new instance every time the bean is requested.
Click to reveal answer
beginner
How do you specify a prototype scope for a bean using @Scope?
Use @Scope("prototype") above the bean class or method to tell Spring to create a new instance each time the bean is requested.Click to reveal answer
intermediate
What scopes are available in Spring Boot besides singleton and prototype?
Other scopes include 'request' (one bean per HTTP request), 'session' (one bean per HTTP session), and 'application' (one bean per ServletContext).
Click to reveal answer
What is the default scope of a Spring bean if @Scope is not used?
✗ Incorrect
By default, Spring beans are singleton scoped, meaning one shared instance per container.
Which @Scope value creates a new bean instance every time it is requested?
✗ Incorrect
The 'prototype' scope creates a new instance each time the bean is requested.
Which scope is best for beans that should live only during a single HTTP request?
✗ Incorrect
The 'request' scope creates one bean instance per HTTP request.
How do you declare a bean with session scope in Spring Boot?
✗ Incorrect
Use @Scope("session") to create one bean instance per HTTP session.
If you want a bean to be shared across the entire web application, which scope should you use?
✗ Incorrect
The 'application' scope shares one bean instance across the whole ServletContext.
Explain how the @Scope annotation affects bean lifecycle and give examples of common scopes.
Think about how many instances are created and how long they live.
You got /3 concepts.
Describe a scenario where using prototype scope is better than singleton scope.
Consider when you want fresh data or state per use.
You got /3 concepts.