Mock tests, Interview questions, Tutorials and Tech news
 
 
Home > Programming / tutorials > Prototype scope in Spring beans

Prototype scope in Spring beans

When you specify a bean as prototype in xml file or through annotation

<bean
id=”myBeanInstance”
class=”com.xyx.PrototypeBeanExample”
scope=”prototype”
autowire=”byName”>

</bean>

it means that every time a request for this bean is made, a new instance is created. If you want to see the illustration

Prototype bean in Spring

Prototype is meant for beans which hold some state.

The  bean lifecycle also changes in prototype bean. From Spring’s doc

Spring does not manage the complete lifecycle of a prototype bean: the container instantiates, configures, decorates and otherwise assembles a prototype object, hands it to the client and then has no further knowledge of that prototype instance

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • IndianPad
  • Reddit
Categories: Programming / tutorials Tags: ,
  1. November 12th, 2010 at 02:27 | #1

    here is a best differentiation of the singleton vs. the prototype scopes of Spring Framework

    http://www.adobocode.com/spring/springs-scopes-singleton-vs-prototype

  1. No trackbacks yet.
Get Adobe Flash playerPlugin by wpburn.com wordpress themes