Creating Singleton and Prototype beans
Creating beans to the containers is not enough for any project specification using the Spring framework. It is always necessary to determine the lifespan of the beans through bean scopes. The following recipe will determine how to optimize a container by creating Singleton and Prototypes beans.
Getting started
The scope of the beans characterizes how many of their instances will be used by the application. It categorizes also the purpose of each bean as to why it is loaded to the Spring container. There are four scopes that can be associated with Spring beans but only two of them will be discussed in this chapter as part of the core platform.
How to do it...
This recipe will be using both ch02-xml
and the ch02-jc
project in declaring which beans are considered Singleton and Prototype. We will explore and identify the effects of applying either of the two scopes to the container:
- Open the project
ch02-xml
and locate the XML definition file in thech02-xml...