When you create a Service bean or Dao bean in your Spring applicationContext.xml file, what is the scope of those beans?
Will every person who accesses the web application use the same instance of the bean, or is the bean instantiated for each user's session?
This scopes the bean definition to a single instance per Spring IoC container (default). This scopes a single bean definition to have any number of object instances. This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
global-session is scope of bean in portlet context.
Explanation: In Spring 1. x, singleton and prototype are the only two valid bean scopes, and they are specified by the singleton attribute (i.e., singleton=”true” or singleton=”false”), not the scope attribute.
By default a bean created in Spring is of scope singleton, so yes each person will access the same instance in those cases. The alternative is to specify the scope as prototype.
More info on this here, sections 3.4.1 and 3.4.2:
http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-scopes-prototype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With