Skip to content
Storing Spring Session into Couchbase
Branch: master
Clone or download
deniswsrosa Update README.adoc
adding support guidelines
Latest commit 409e056 Jun 1, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.mvn/wrapper first commit Apr 5, 2019
ci first commit Apr 5, 2019
config/checkstyle first commit Apr 5, 2019
eclipse first commit Apr 5, 2019
src/main Adjusting Docs Apr 5, 2019
.gitignore first commit Apr 5, 2019
CODE_OF_CONDUCT.adoc first commit Apr 5, 2019
CONTRIBUTING.adoc first commit Apr 5, 2019
LICENSE.txt first commit Apr 5, 2019
README.adoc Update README.adoc May 31, 2019
mvnw first commit Apr 5, 2019
mvnw.cmd first commit Apr 5, 2019
pom.xml fixing group id May 7, 2019
settings.xml first commit Apr 5, 2019


Spring Session Couchbase

Spring Session Couchbase provides a solution for Spring Session in a Couchbase data store.

  • Accessing a session from any environment (i.e. web, messaging infrastructure, etc)

  • In a web environment

    • Support for clustering in a vendor neutral way

    • Pluggable strategy for determining the session id

    • Easily keep the HttpSession alive when a WebSocket is active

Import Spring Session Couchbase

Simply add to your pom.xml the following dependency pom.xml


Spring Configuration

After adding the required dependencies, we can create our Spring configuration. The Spring configuration is responsible for creating a Servlet Filter that replaces the HttpSession implementation with an implementation backed by Spring Session.

All you have to do is to add the following Spring Configuration:

public class MyApplication {

	public static void main(String[] args) {, args);

  1. The @EnableCouchbaseHttpSession annotation creates a Spring Bean with the name of springSessionRepositoryFilter that implements Filter. The filter is what is in charge of replacing the HttpSession implementation to be backed by Spring Session. In this instance Spring Session is backed by Couchbase.

The @EnableCouchbaseHttpSession has 4 properties:

  • maxInactiveIntervalInSeconds (default 1800 seconds) - How long the session will live before expiring

  • typeName (default "_type" ) - The name of the attribute that is going to be used as the type of the document

  • typeValue (default "sessions" ) - The value of the type attribute that is going to be used to differentiate this document from others.

  • keepStringAsLiteral (default false) - Any attribute in the session which is a String will be saved as a document attribute instead of being serialized in a binary format. This is really useful if you need to query the user’s session via N1QL (Ex: create a dashboard of what users have in their sessions). Check out this example to see it working

Configuring the Couchbase Connection

Spring Boot automatically creates a Couchbase connection and connects Spring Session to a Couchbase Server. You can configure this connection by defining a @Configuration class which extends or via :


Servlet Container Initialization

Our Spring Configuration created a Spring Bean named springSessionRepositoryFilter that implements Filter. The springSessionRepositoryFilter bean is responsible for replacing the HttpSession with a custom implementation that is backed by Spring Session.

In order for our Filter to do its magic, Spring needs to load our Config class. Last we need to ensure that our Servlet Container (i.e. Tomcat) uses our springSessionRepositoryFilter for every request. Fortunately, Spring Boot takes care of both of these steps for us.

Couchbase Sample Application

The repo contains a fully functional example, please check the documentation in the sample to find out how to run it.

Spring Session Project Site

You can find the documentation, issue management, support, samples, and guides for using Spring Session Couchbase at


Spring Session is Open Source software released under the Apache 2.0 license.


This is a community project mainly supported by me. If you have any questions feel free to ping me at @deniswsrosa

You can’t perform that action at this time.