How to configure spring-session with spring-boot WITHOUT Redis and without auto configuration to use another db store

Selwyn picture Selwyn · Jan 17, 2016 · Viewed 8.1k times · Source

I would like to utilize spring-boot + spring-session WITHOUT Redis but use dynamodb as the sessionRepository implementation.

All of the examples available are tightly coupled with Redis or Hazelcast and are mostly auto configurations that abstract away what beans are being initialized. Moreover, my spring boot config explicitly defines a

@Bean
    public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory(Environment env) {

        TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();

return factory;
}

I have also disabled the spring-boot autoconfiguration SessionAutoConfiguration.class for spring-session.

So I have a couple of questions.

1. How do I configure my spring-boot project that has an explicitly defined TomcatEmbeddedServletContainerFactory bean to utilize use spring-session?

2. I noticed spring-session is tightly coupled with Redis and Hazelcast (and nothing else). Are there any objections to using a store like amazon dynamodb for the session repository impl?

I was looking at https://github.com/spring-projects/spring-session/blob/master/spring-session/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java

to give me an idea of how to configure what I want to achieve but I keep running into initialization exceptions. If somebody could point in the right direction I would greatly appreciate it.

using spring-session version: 1.1.0.M1

Answer

Rob Winch picture Rob Winch · Jan 21, 2016

I have also disabled the spring-boot autoconfiguration SessionAutoConfiguration.class for spring-session.

If you do not have Redis on your classpath you should not need to disable the auto configuration.

How do I configure my spring-boot project that has an explicitly defined TomcatEmbeddedServletContainerFactory bean to utilize use spring-session?

The 1.1.0.M1 reference discusses how to do this with @EnableSpringHttpSession. For example:

@EnableSpringHttpSession
@Configuration
public class SpringHttpSessionConfig {
        @Bean
        public CusttomSessionRepository sessionRepository() {
                return new CusttomSessionRepository();
        }
}

I noticed spring-session is tightly coupled with Redis and Hazelcast (and nothing else). Are there any objections to using a store like amazon dynamodb for the session repository impl?

We would love contributions for different data stores (in fact we are getting support for GemFire). The problem is really more about time to implement them all.

to give me an idea of how to configure what I want to achieve but I keep running into initialization exceptions.

It sounds as you are trying some of the suggestions I have provided. However, I cannot help unless you provide details about the exceptions you are getting.