title: Spring-Boot: Exception when using Redis as a Session Store
body: <p>I'm trying to create a minimal web application using spring-boot which makes use of redis as a session store. The goal is to share session state between multiple instances of the web application. The application works fine without Redis (using "normal" sessions) but throws an exception after I enabled the configuration for Redis. I followed this <a href="http://altfatterz.blogspot.de/2015/02/spring-boot-with-angularjs-form.html" rel="nofollow">tutorial</a>. The application is started via "java -jar path_to.jar". </p>
  
  <p>To make the app work again, it is sufficient to comment out the configuration class (see below).</p>
  
  <p>The first attempt included the deployment to Heroku, but it's the same problem on my machine using a local Redis server. The environment variable for the connection string is set up properly. </p>
  
  <p>The whole application consists only of the snippets shown below. Am I missing something? Thank you.</p>
  
  <p><strong>Configuration:</strong></p>
  
  <pre><code>@Profile("production")
  @Configuration
  @EnableRedisHttpSession
  public class ProductionRedisConfiguration {
  
      @Bean
      public JedisConnectionFactory connectionFactory() throws URISyntaxException {
          JedisConnectionFactory redis = new JedisConnectionFactory();
          String redisUrl = System.getenv("REDISCLOUD_URL");
  
          URI redisUri = new URI(redisUrl);
          redis.setHostName(redisUri.getHost());
          redis.setPort(redisUri.getPort());
          redis.setPassword(redisUri.getUserInfo().split(":",2)[1]);
          return redis;
      }
  
      static class Initializer  extends AbstractHttpSessionApplicationInitializer {
          public Initializer() {
              super(ProductionRedisConfiguration.class);
          }
      }
  }
  </code></pre>
  
  <p><strong>"App":</strong></p>
  
  <pre><code>@EnableAutoConfiguration
  @ComponentScan
  public class Application {
      private static final Logger LOGGER = getLogger(Application.class);
      public static void main(String[] args) throws Throwable {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>@Controller
  public class GreetingController {
  
      @RequestMapping("/")
      public @ResponseBody String session(HttpServletRequest request) {
          String name = (String) request.getSession().getAttribute("name");
          if(name != null) {
              return "Hello, " + name;
          } else {
              String newName = "User " + new Random().nextInt(1000000);
              request.getSession().setAttribute("name", newName);
              return "No session found, you are now called " + newName;
          }
      }
  }
  </code></pre>
  
  <p><strong>Dependencies:</strong></p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
          &lt;artifactId&gt;spring-session&lt;/artifactId&gt;
          &lt;version&gt;1.0.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-redis&lt;/artifactId&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>Trace:</strong></p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
          at java.lang.Thread.run(Unknown Source)
  Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.c
  ontext.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
          at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:140)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
          at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:124)
          at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:609)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:806)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:795)
          at com.backbase.progfun.Application.main(Application.java:17)
          ... 6 more
  Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
          at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:104)
          at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.&lt;init&gt;(TomcatEmbeddedServletContainer.java:67)
          at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServ
  letContainerFactory.java:258)
          at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletCon
  tainerFactory.java:138)
          at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:1
  60)
          at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
          ... 13 more
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
          at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
          at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:77)
          ... 18 more
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
          at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
          ... 20 more
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
          at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
          ... 22 more
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
          at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
          at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
          ... 24 more
  </code></pre>