Annotation Interface EnableJdbcHttpSession


@Retention(RUNTIME) @Target(TYPE) @Documented @Import(JdbcHttpSessionConfiguration.class) @Configuration(proxyBeanMethods=false) public @interface EnableJdbcHttpSession
Add this annotation to an @Configuration class to expose the SessionRepositoryFilter as a bean named springSessionRepositoryFilter and backed by a relational database. In order to leverage the annotation, a single DataSource must be provided. For example:
 @Configuration
 @EnableJdbcHttpSession
 public class JdbcHttpSessionConfig {

     @Bean
     public DataSource dataSource() {
         return new EmbeddedDatabaseBuilder()
                 .setType(EmbeddedDatabaseType.H2)
                 .addScript("org/springframework/session/jdbc/schema-h2.sql")
                 .build();
     }

     @Bean
     public PlatformTransactionManager transactionManager(DataSource dataSource) {
         return new DataSourceTransactionManager(dataSource);
     }

 }
 
More advanced configurations can extend JdbcHttpSessionConfiguration instead. For additional information on how to configure data access related concerns, please refer to the Spring Framework Reference Documentation.
Since:
1.2.0
See Also:
  • Element Details

    • maxInactiveIntervalInSeconds

      int maxInactiveIntervalInSeconds
      The session timeout in seconds. By default, it is set to 1800 seconds (30 minutes). This should be a non-negative integer.
      Returns:
      the seconds a session can be inactive before expiring
      Default:
      1800
    • tableName

      String tableName
      The name of database table used by Spring Session to store sessions.
      Returns:
      the database table name
      Default:
      "SPRING_SESSION"
    • cleanupCron

      String cleanupCron
      The cron expression for expired session cleanup job. By default runs every minute.
      Returns:
      the session cleanup cron expression
      Since:
      2.0.0
      Default:
      "0 * * * * *"
    • flushMode

      FlushMode flushMode
      Flush mode for the sessions. The default is ON_SAVE which only updates the backing database when SessionRepository.save(Session) is invoked. In a web environment this happens just before the HTTP response is committed.

      Setting the value to IMMEDIATE will ensure that the any updates to the Session are immediately written to the database.

      Returns:
      the flush mode
      Since:
      2.2.0
      Default:
      ON_SAVE
    • saveMode

      SaveMode saveMode
      Save mode for the session. The default is SaveMode.ON_SET_ATTRIBUTE, which only saves changes made to session.
      Returns:
      the save mode
      Since:
      2.2.0
      Default:
      ON_SET_ATTRIBUTE