使用 spring-data-jdbc 和 spring-session-redis

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

看来spring-data-jdbc和spring-session-redis不能一起工作,至少在没有额外配置的情况下不能。

我是不是漏掉了什么?

这是我的错误:

.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.

仅使用 spring 数据-jdbc 效果很好。

spring-session-data-redis依赖引入了spring-data-redis依赖。

由于您也使用 spring-data-jdbc,Spring 数据需要一种方法来区分它应该使用哪种持久化技术。

由于应用有多个Spring数据模块,Spring数据进入严格存储库配置模式。

您应该会在日志中看到以下消息

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

这意味着 Spring Data 将查找有关存储库或域的详细信息 class 以决定 Spring 数据模块绑定。

在这种情况下,由于您想为您的域 class 使用 JDBC,因此您应该使用 @Table.

对其进行注释

例如:

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

@Table
class Person { … }

reference documentation.

中有一节关于使用具有多个 Spring 数据模块的存储库