Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is difference between singleton and prototype bean?
Answer: Basically a bean has scopes which defines their existence on the application

Singleton: means single bean definition to a single object instance per Spring IOC container.

Prototype: means a single bean definition to any number of object instances.

Whatever beans we defined in spring framework are singleton beans. There is an attribute in bean tag named ‘singleton’ if specified true then bean becomes singleton and if set to false then the bean becomes a prototype bean. By default it is set to true. So, all the beans in spring framework are by default singleton beans.

<bean id="createNewStock" class="springexample.stockMarket.CreateNewStockAccont" singleton="false">
<property name="newBid"/>
</bean>
Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook