From the course: Spring: Framework in Depth

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Bean scopes

Bean scopes

From the course: Spring: Framework in Depth

Start my 1-month free trial

Bean scopes

- There's a concept in Spring of Bean Scopes that is very important to understand. Well they aren't used that often in normal practice, it is important to be exposed to them, so that you can use them whenever you may need to. The most common bean scope is the Singleton Scope. The singleton is the default scope of all beans defined for the application context. If you did not specify a specific scope, you get a singleton, you get one instance of the object per context definition. Now you can declare two beans of the same type in a context, but you have to do some work to get them injected properly and most often, this becomes very cumbersome and isn't recommended. One thing to be aware of as we previously mentioned, is that you need to be careful with state because you have one instance of the class all state essentially becomes available to all instances of the object so even though there's only one instance, every…

Contents