Skip to content
Ameen Abozaid
Planned lessonJNR-010-L04

Bean scopes

  • Lesson 4 of 6
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

pick singleton or prototype.

Planned topics

  • Singleton (default): one shared instance per container.
  • Prototype: a new instance each time it is requested.
  • Web scopes (request, session) exist; use them rarely.
  • Almost all Shop beans are singletons.
  • A prototype injected into a singleton is created only once, at injection time.
Draft outline details

Demonstration

java
@Component @Scope("prototype") class ReportBuilder {}

Check your understanding

What is the default scope?

Show answer

Singleton.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.