What is the difference between a Singleton and Prototype bean in Spring?

  • Every bean in Spring has a scope that defines its existence timeframe in the application.
  • Singleton scope for bean limits a bean to a single object instance per Spring IOC container.
  • This single instance is limited to a specific ApplicationContext. If there are multiple ApplicationContext then we can have more than one instance of bean.
  • By default all the beans in Spring framework are Singleton scope beans.
  • With Prototype scope a single bean definition can have multiple object instances in a Spring container.
  • In prototype scope bean, the Spring IoC container creates new bean instance of the object every time a request for that specific bean is made.