@Retention(value=RUNTIME) @Target(value=TYPE) @Documented @Import(value=JdbcHttpSessionConfiguration.class) @Configuration(proxyBeanMethods=false) public @interface EnableJdbcHttpSession
@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.EnableSpringHttpSession| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
cleanupCron
The cron expression for expired session cleanup job.
|
org.springframework.session.FlushMode |
flushMode
Flush mode for the sessions.
|
int |
maxInactiveIntervalInSeconds
The session timeout in seconds.
|
org.springframework.session.SaveMode |
saveMode
Save mode for the session.
|
java.lang.String |
tableName
The name of database table used by Spring Session to store sessions.
|
public abstract int maxInactiveIntervalInSeconds
public abstract java.lang.String tableName
public abstract java.lang.String cleanupCron
public abstract org.springframework.session.FlushMode flushMode
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.