使用spring-data-jdbc和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 data-jdbc就像一种魅力。

解决方法

spring-session-data-redis依赖项带来了spring-data-redis依赖项。

由于您还使用了spring-data-jdbc,因此Spring Data需要一种方法来区分应使用的持久性技术。

由于应用程序具有多个Spring Data模块,因此Spring Data进入严格的存储库配置模式。

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

找到了多个Spring Data模块,进入了严格的存储库配置模式!

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

在这种情况下,由于要对域类使用JDBC,因此应使用@Table对其进行注释。

例如:

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

@Table
class Person { … }

reference documentation中有一节关于将存储库与多个Spring Data模块一起使用。