Class SpringHttpSessionConfiguration
java.lang.Object
org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware
@Configuration(proxyBeanMethods=false)
public class SpringHttpSessionConfiguration
extends Object
implements org.springframework.beans.factory.InitializingBean, 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
SessionCreatedEventandSessionDestroyedEvent.
- Since:
- 1.1
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetCookieSerializer(CookieSerializer cookieSerializer) voidsetHttpSessionIdResolver(HttpSessionIdResolver httpSessionIdResolver) voidsetHttpSessionListeners(List<jakarta.servlet.http.HttpSessionListener> listeners) voidsetServletContext(jakarta.servlet.ServletContext servletContext) <S extends Session>
SessionRepositoryFilter<? extends Session>springSessionRepositoryFilter(SessionRepository<S> sessionRepository)
-
Constructor Details
-
SpringHttpSessionConfiguration
public SpringHttpSessionConfiguration()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
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:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setServletContext
@Autowired(required=false) public void setServletContext(jakarta.servlet.ServletContext servletContext) -
setCookieSerializer
-
setHttpSessionIdResolver
@Autowired(required=false) public void setHttpSessionIdResolver(HttpSessionIdResolver httpSessionIdResolver) -
setHttpSessionListeners
@Autowired(required=false) public void setHttpSessionListeners(List<jakarta.servlet.http.HttpSessionListener> listeners)
-