3

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

Thomas Lang
  • 1,285
  • 17
  • 35

3 Answers3

2

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.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Thomas Lang
  • 1,285
  • 17
  • 35
  • 1
    Not sure but I suspect that this is due to [DATAJDBC-437](https://jira.spring.io/browse/DATAJDBC-437), which enforces strict checking when multiple modules for Spring Data are detected (which is the case due to the Spring Data LDAP dependency). – M. Deinum Nov 18 '19 at 13:17
  • 2
    I added some background to the answer. – Jens Schauder Nov 19 '19 at 05:25
1

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.

Thomas Lang
  • 1,285
  • 17
  • 35
0

Put a @Repository at your repositories.

JPABuddy does not do it per default, so I landed here.
These conslusion is already pointed out in the comments, but for the record, we need an answer. :)

akop
  • 5,981
  • 6
  • 24
  • 51