Marketplace for Content, Tests and Assessment
 
 
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

Categories: Programming / tutorials Tags: ,
  1. No comments yet.
  1. No trackbacks yet.
Get Adobe Flash playerPlugin by wpburn.com wordpress themes