60 seconds to Spring （2）
60 sec to Spring [TOC]
Bean Tutorial 2 - To Singleton or Not To Singleton
Beans are defined to be deployed in one of the two modes: Singleton and Non-Singleton (Prototype). When a bean is a singleton, only one shared instance of the bean will be managed. The prototype mode of a bean deployment results in the creation of a new bean instance every time a request for that specific bean is done. Tutorial 2 will demostrate the difference behaviour when defining a bean as Singleton and Prototype.
Note: By default all beans are deployed in singleton mode, unless you specify otherwise.
Step 1: Create a CounterBean.java in src
Step 2: Specify the CounterBean class in the bean.xml
Do notice that I have defined one CounterBean as singleton bean and the other as prototype bean.
Step 3: Create a Main.java in src
Step 4: Use an ANT script to build and execute the Main class. Just run ant from the command prompt will do the trick.
Below are the output from ANT.