NoSuchBeanDefinitionException after update to spring boot 2.2.1

∥☆過路亽.° 提交于 2020-01-25 00:20:07

问题


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: {}

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.

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

Any hints?

EDIT
Entity

@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;
}

Repository

interface IEstablishmentRepository extends CrudRepository<Establishment, Long>

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:

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 :)


回答1:


Should have read the console output with more passion:

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.

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

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.




回答2:


Just some side information on this topic:
if you leave out the spring-data-ldap dependency from the spring-boot-starter-parent package and replace it with the spring-ldap-core then the issue with multiple modules for spring data isn´t there anymore.
So if you just use/depend on the ldapTemplate from spring-ldap-core then everything is fine.



来源:https://stackoverflow.com/questions/58912292/nosuchbeandefinitionexception-after-update-to-spring-boot-2-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!