Search code examples
javajdbcspring-bootspring-session

Use existing Spring Boot dataSource for spring-session-jdbc


In my spring-boot application I have an existing dataSource, which I use for Hibernate and/or JdbcTemplate.

I am planning to use spring-session with spring-session-jdbc in the future.

Can the already existing and configured dataSource of the application be used?

If yes, how?

Or do I need to configure an additional dataSource for spring-session-jdbc?


Solution

  • The answer is:

    Yes, it is possible, like the documentation of the newly released Spring Session 1.2.0 states:

    http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc-boot.html#httpsession-jdbc-boot-configuration

    It also works without Spring Boot. In an old Spring-MVC project based on xml-config, which does not use Spring Boot, the configured dataSource is automatically used by Spring Session.