3

将现有代码从 spring boot 2.2.0 升级到 2.2.1 后,我遇到了一个奇怪的问题。
似乎我的 spring 数据 jdbc 存储库不再以某种方式被扫描:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'de.thd.dmpk.establishmentmanagement.IEstablishmentRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

此外,在引导 2.2.1 中也有此信息调试行:

Spring Data JDBC - Could not safely identify store assignment for repository candidate interface de.thd.dmpk.establishmentmanagement.IEstablishmentRepository. 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.

当我将所有内容切换回引导 2.2.0 时,信息消息以及上述异常都消失了。

有什么提示吗?

编辑
实体

@Getter
@RequiredArgsConstructor(staticName = "of", access = AccessLevel.PUBLIC, onConstructor = @__({@PersistenceConstructor}))
@EqualsAndHashCode
public final class Establishment {

private final @Id
@With
long establishmentId;

@NotNull
@NotEmpty
@Size(max = 255)
private final
String establishmentName;
}

存储库

interface IEstablishmentRepository extends CrudRepository<Establishment, Long>

到目前为止,@Table如果您不想更改数据库上的表名,则不需要注释。此外@EnableJdbcRepositories,以这种方式扫描每个文档:

如果没有配置基本包,则使用配置类所在的包。 https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.java-config

那里发生了奇怪的事情:)

4

2 回答 2

2

应该更加热情地阅读控制台输出:

Spring Data JDBC - 无法安全地识别存储库候选接口 de.thd.dmpk.establishmentmanagement.IEstablishmentRepository 的存储分配。如果您希望此存储库成为 JDBC 存储库,请考虑使用以下注释之一来注释您的实体:org.springframework.data.relational.core.mapping.Table。

用注释我的实体@Table就可以了。放在我的实体上后一切正常。

这背后的原因是DATAJDBC-437。当 Spring Data JDBC 与其他 Spring Data Modules 一起使用时,Spring Data JDBC 过去感觉要对所有存储库负责,从而导致每个接口有多个 bean。为了避免这种情况@Table,在被视为 JDBC 存储库主题的聚合根上需要注释。

于 2019-11-18T13:05:09.967 回答
1

关于这个主题的一些附带信息:
如果您spring-data-ldap从包中省略依赖项spring-boot-starter-parent并将其替换为,spring-ldap-core那么 spring 数据的多个模块的问题就不再存在了。
所以如果你只是使用/依赖ldapTemplatefromspring-ldap-core那么一切都很好。

于 2019-11-25T08:18:25.037 回答