Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Service default scope

Tags:

java

scope

spring

Which is the default scope of a Spring 4 @Service?

Does it make sense designing a Service implementation to store info about the current logged user (according to the current HTTP session), through class attributes (also by using the final modifier)?

like image 941
vdenotaris Avatar asked Aug 30 '14 14:08

vdenotaris


People also ask

What is the default scope in Spring?

Spring's default scope is singleton.

Is @service singleton in Spring?

singleton is the default scope in spring, so just leave your bean definitions as they are, without explicitly specifying the scope attribute. You can read more about scopes in the spring docs.

Are @bean singletons?

Singleton Scope:By default, the scope of a bean is a singleton.

What are the scopes in Spring?

The Spring Framework supports the following five scopes, three of which are available only if you use a web-aware ApplicationContext. Sr.No. 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.


1 Answers

Which is the default scope of a Spring 4 @Service?

The default scope is singleton

It is reasonable to design a Service implementation in order to store some info, related to the current logged user (according to the current HTTP session)

Yes. In that case, the service will have to have the scope "session". See http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-scopes-other

like image 127
JB Nizet Avatar answered Oct 20 '22 13:10

JB Nizet