title: Spring Session with JDBC - How to Use a Separate DB as a Session Store
body: <p>I am working on an application that uses Spring Session JDBC. I also am using Spring JPA for other entities. My question is, how does one configure a Spring Boot application to allow for a separate database to be used for Session storage?</p>
  
  <p>I have referenced this <a href="https://stackoverflow.com/questions/45769603/creating-separate-data-source-for-my-session-spring-using-jdbc-and-spring-data-j">question</a>, but it appears the JdbcHttpSessionConfiguration constructor noted in the answer is no longer valid (I am using Spring Boot 2.1.1). Other than that, I was unable to find any documentation on the subject. I found information on how to configure Spring Session with a JDBC backing, and how to use multiple data sources in Spring, but not how to combine the two. I reckon it might involves extending <code>JdbcHttpSessionConfiguration</code>, but unfortunately, I am not able to figure out how to properly do so.</p>
  
  <p>This is all I have thus far:</p>
  
  <pre><code>    @Configuration
  class SessionConfig extends JdbcHttpSessionConfiguration {
  
      @Bean
      public DataSource dataSource() {
          return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
      }
  
  }
  </code></pre>
  
  <p>However, the above attempts to create all my entity tables in the H2 store as well. </p>
  
  <p>My primary datasource (PostgreSQL) is specified in my <code>application.properties</code>.</p>
  
  <pre><code>spring.session.store-type=jdbc
  spring.datasource.url=jdbc:postgresql://localhost/auth
  spring.datasource.username=xxx
  spring.datasource.password=xxx
  spring.datasource.driverClassName=org.postgresql.Driver
  spring.jpa.show-sql=true
  spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
  </code></pre>
  
  <p>Thanks for any guidance.</p>