Annotation Interface EnableJdbcHttpSession
@Retention(RUNTIME)
@Target(TYPE)
@Documented
@Import(JdbcHttpSessionConfiguration.class)
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(proxyBeanMethods = false) @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:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionThe cron expression for expired session cleanup job.Flush mode for the sessions.int
The session timeout in seconds.Save mode for the session.The name of database table used by Spring Session to store sessions.
-
Element Details
-
maxInactiveIntervalInSeconds
int maxInactiveIntervalInSecondsThe 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 tableNameThe name of database table used by Spring Session to store sessions.- Returns:
- the database table name
- Default:
- "SPRING_SESSION"
-
cleanupCron
String cleanupCronThe 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 flushModeFlush mode for the sessions. The default isON_SAVE
which only updates the backing database whenSessionRepository.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 saveModeSave mode for the session. The default isSaveMode.ON_SET_ATTRIBUTE
, which only saves changes made to session.- Returns:
- the save mode
- Since:
- 2.2.0
- Default:
- ON_SET_ATTRIBUTE
-