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 SessionCreatedEvent and SessionDestroyedEvent.
Since:
1.1
See Also:
  • Constructor Details

    • SpringHttpSessionConfiguration

      public SpringHttpSessionConfiguration()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • sessionEventHttpSessionListenerAdapter

      @Bean public SessionEventHttpSessionListenerAdapter 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 interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • setServletContext

      @Autowired(required=false) public void setServletContext(jakarta.servlet.ServletContext servletContext)
    • setCookieSerializer

      @Autowired(required=false) public void setCookieSerializer(CookieSerializer cookieSerializer)
    • setHttpSessionIdResolver

      @Autowired(required=false) public void setHttpSessionIdResolver(HttpSessionIdResolver httpSessionIdResolver)
    • setHttpSessionListeners

      @Autowired(required=false) public void setHttpSessionListeners(List<jakarta.servlet.http.HttpSessionListener> listeners)