更新到 spring boot 2.2.1 后的 NoSuchBeanDefinitionException [英] NoSuchBeanDefinitionException after update to spring boot 2.2.1

查看:27
本文介绍了更新到 spring boot 2.2.1 后的 NoSuchBeanDefinitionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I face a strange issue after upgrading my existing code from spring boot 2.2.0 to 2.2.1.
It seems that my spring data jdbc repositories are not getting scanned anymore somehow:

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 中也有此信息调试行:

Furthermore this informational debug line is there as well with boot 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 时,信息消息以及上述异常都消失了.

When i switch everything back to boot 2.2.0 the info message as well as the exceptions above are disappearing.

有什么提示吗?

编辑
实体

@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 以这种方式扫描每个文档:

Up to now a @Table Annotation was not necessary if you don´t want to change the table name on the db. Furthermore @EnableJdbcRepositories scans per documentation that way:

如果没有配置基础包,则使用其中包含的包配置类驻留.https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.java-config

If no base package is configured, it uses the package in which the configuration class resides. https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.java-config

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

Strange things going on there :)

推荐答案

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

Should have read the console output with more passion:

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

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.

@Table 注释我的实体就可以了.放入我的实体后,一切正常.

Annotating my entities with @Table does the job. Everything´s working after being put onto my entities.

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

The reason behind this is DATAJDBC-437. When Spring Data JDBC is used with other Spring Data Modules, Spring Data JDBC used to feel responsible for all reposities, resulting in multiple beans per interface. In order to avoid that in such a scenario @Table annotations are required on the aggregate roots that are to be considered subject of JDBC repositories.

这篇关于更新到 spring boot 2.2.1 后的 NoSuchBeanDefinitionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆