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:
-
EnableSpringHttpSession
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe cron expression for expired session cleanup job.org.springframework.session.FlushModeFlush mode for the sessions.intThe session timeout in seconds.org.springframework.session.SaveModeSave 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
org.springframework.session.FlushMode flushModeFlush mode for the sessions. The default isON_SAVEwhich 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
IMMEDIATEwill 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
org.springframework.session.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
-