Class SpringHttpSessionConfiguration
java.lang.Object
org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
HazelcastHttpSessionConfiguration
,JdbcHttpSessionConfiguration
,MongoHttpSessionConfiguration
,RedisHttpSessionConfiguration
@Configuration(proxyBeanMethods=false)
public class SpringHttpSessionConfiguration
extends Object
implements org.springframework.context.ApplicationContextAware
Configures the basics for setting up Spring Session in a web environment. In order to
use it, you must provide a
SessionRepository
. For example:
@Configuration @EnableSpringHttpSession public class SpringHttpSessionConfig { @Bean public MapSessionRepository sessionRepository() { return new MapSessionRepository(new ConcurrentHashMap<>()); } }
It is important to note that no infrastructure for session expirations is configured for you out of the box. This is because things like session expiration are highly implementation dependent. This means if you require cleaning up expired sessions, you are responsible for cleaning up the expired sessions.
The following is provided for you with the base configuration:
- SessionRepositoryFilter - is responsible for wrapping the HttpServletRequest with an implementation of HttpSession that is backed by a SessionRepository
- SessionEventHttpSessionListenerAdapter - is responsible for translating Spring
Session events into HttpSessionEvent. In order for it to work, the implementation of
SessionRepository you provide must support
SessionCreatedEvent
andSessionDestroyedEvent
.
- Since:
- 1.1
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
init()
void
setApplicationContext
(org.springframework.context.ApplicationContext applicationContext) void
setCookieSerializer
(CookieSerializer cookieSerializer) void
setHttpSessionIdResolver
(HttpSessionIdResolver httpSessionIdResolver) void
setHttpSessionListeners
(List<javax.servlet.http.HttpSessionListener> listeners) void
setServletContext
(javax.servlet.ServletContext servletContext) <S extends Session>
SessionRepositoryFilter<? extends Session>springSessionRepositoryFilter
(SessionRepository<S> sessionRepository)
-
Constructor Details
-
SpringHttpSessionConfiguration
public SpringHttpSessionConfiguration()
-
-
Method Details
-
init
@PostConstruct public void init() -
sessionEventHttpSessionListenerAdapter
-
springSessionRepositoryFilter
@Bean public <S extends Session> SessionRepositoryFilter<? extends Session> springSessionRepositoryFilter(SessionRepository<S> sessionRepository) -
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setServletContext
@Autowired(required=false) public void setServletContext(javax.servlet.ServletContext servletContext) -
setCookieSerializer
-
setHttpSessionIdResolver
@Autowired(required=false) public void setHttpSessionIdResolver(HttpSessionIdResolver httpSessionIdResolver) -
setHttpSessionListeners
@Autowired(required=false) public void setHttpSessionListeners(List<javax.servlet.http.HttpSessionListener> listeners)
-