Search code examples
springjdbcredisspring-dataspring-session

Using spring-data-jdbc and spring-session-redis


It seems that spring-data-jdbc and spring-session-redis can't work together, at least not without any additional configuration.

Am I missing something?

Here is my error:

.RepositoryConfigurationExtensionSupport : Spring Data JDBC - Could not safely identify store assignment for repository candidate interface ca.code3.timekeeper.repository.ClientRepository. If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations: org.springframework.data.relational.core.mapping.Table.

Using only spring data-jdbc works like a charm.


Solution

  • The spring-session-data-redis dependency brings in the spring-data-redis dependency.

    Since you also use spring-data-jdbc, Spring Data needs a way to distinguish which persistence technology it should use.

    Since the application has multiple Spring Data modules, Spring Data enters strict repository configuration mode.

    You should see the following message in your logs

    Multiple Spring Data modules found, entering strict repository configuration mode!

    This means that Spring Data will look for details on the repository or the domain class to decide about Spring Data module binding.

    In this case, since you want to use JDBC for your domain class, you should annotate it with @Table.

    For example:

    interface PersonRepository extends CrudRepository<Person, Long> { … }
    
    @Table
    class Person { … }
    

    There is a section about using repositories with multiple Spring Data modules in the reference documentation.