Spring Boot provides auto-configuration Spring Session for a wide range of data stores. When creating a servlet web application, the following stores can be automatically configured:
-
JDBC
-
Redis
-
Hazelcast
-
MongoDB
In addition, Spring Boot for Apache Geode provides auto-configuration for use Apache Geode as a session store.
Servlet autoconfiguration replaces the need to use the @Enable*HttpSession
annotation.
When building a reactive web application, the following stores can be automatically configured:
-
Redis
-
MongoDB
Reactive autoconfiguration replaces the need to use the @Enable*WebSession
annotation.
If there is one Spring Session module in the classpath, Spring Boot automatically uses that storage implementation. If there is more than one implementation, you must select StoreType
that you want to use to store sessions. For example, to use JDBC as backend storage, you can configure your application as follows:
spring.session.store-type=jdbc
spring:
session:
store-type: "jdbc"
store-type
to
none
.
Each repository has certain additional parameters. For example, you can customize the table name for a JDBC store, as shown in the following example:
spring.session.jdbc.table-name=SESSIONS
spring:
session:
jdbc:
table-name: "SESSIONS"
To set the session timeout, you can use the spring.session.timeout
property. If this property is not set in a servlet web application, autoconfiguration will fall back to server.servlet.session.timeout
.
You can manage Spring Session configuration using the @Enable*HttpSession
annotation (servlet application) or the @Enable*WebSession
annotation (reactive application). This will rollback the auto-configuration. The Spring Session can then be configured using annotation attributes rather than the configuration properties described previously.
GO TO FULL VERSION