60 seconds to Spring (2)

60 sec to Spring [TOC]

ruler.gif

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

org/jarchitect/spring/tutorial2/CounterBean.java

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.

        <beans>             </beans>

Step 3: Create a Main.java in src

org/jarchitect/spring/tutorial2/Main.java

 org.jarchitect.spring.tutorial2;                                                                           }

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.

                   

Done.

[TOC]

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页