Spring Data JDBC logs 'Could not safely identify store assignment'
Spring Data JDBC - Could not safely identify store assignment for repository candidate interfaceShort answer
Spring Data found more than one store module on the classpath, for example JPA and JDBC, so it entered strict mode and skipped a repository that carries no JDBC mark. The log line is informational. If the repository should be a JDBC repository, annotate its entity with @Table. If not, you can ignore the line.
Fix it fast
1Find out which cause you have
List which Spring Data starters are on the classpath. Two or more store modules is what turns strict mode on.
./mvnw dependency:tree | grep -i "spring-data" # Gradle: ./gradlew dependencies --configuration runtimeClasspath | grep -i spring-data2Match what you see, then jump to its fix
- 1
A repository bean you expected is missing, and this log line names its interfaceThe entity is meant for JDBC but has no @Table annotationFix - 2
The named repository is a JPA repository that works fineThe repository belongs to JPA, and JDBC is only skipping itFix - 3
Several repositories extend only Repository or CrudRepository and the store cannot be told apartRepositories of both stores live in the same package and extend generic interfacesFix
- 1
What does the error look like?
Spring Data JDBC - Could not safely identify store assignment for repository candidate interfaceIf you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations
Cause 1 of 3
The entity is meant for JDBC but has no @Table annotation
1Check
In strict mode Spring Data JDBC only accepts a domain type that carries the @Table annotation from org.springframework.data.relational.core.mapping. Without it, the repository is not registered.
grep -rn "@Table" src/main/java2Fix
Add the annotation to the entity.
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;
@Table("customers")
public class Customer {
@Id Long id;
String name;
}3Verify
Start the app: the line is gone for this repository and it is injected.
./mvnw spring-boot:runConfirmed by raw.githubusercontent.com
Cause 2 of 3
The repository belongs to JPA, and JDBC is only skipping it
1Check
A repository that extends JpaRepository, or whose entity is annotated with JPA's @Entity, is a valid candidate for JPA only. The JDBC module reports that it skipped it. Nothing is broken.
grep -rn "extends JpaRepository\|@Entity" src/main/java2Fix
No change is needed. If you do not use JDBC repositories at all, remove the spring-boot-starter-data-jdbc dependency so only one store module remains.
<!-- pom.xml: remove if unused -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>3Verify
After the dependency is removed, the line no longer appears.
./mvnw spring-boot:runConfirmed by docs.spring.io
Cause 3 of 3
Repositories of both stores live in the same package and extend generic interfaces
1Check
Strict mode binds a repository to a module when it extends a module-specific interface, or when its domain class has the module's annotation. A repository that extends only Repository or CrudRepository, with an entity that has no store annotation, cannot be bound.
grep -rn "extends CrudRepository\|extends Repository" src/main/java2Fix
Mark each entity for its store, or scope each store to its own packages with base packages.
@EnableJdbcRepositories(basePackages = "com.example.jdbc")
@EnableJpaRepositories(basePackages = "com.example.jpa")
class DataConfig { }3Verify
Start the app and check that each repository binds to the intended store.
./mvnw spring-boot:runConfirmed by docs.spring.io
How do I stop it coming back?
- Use one Spring Data store per service where you can, so strict mode never starts.
- When you mix stores, keep their repositories and entities in separate packages.
- Do not put JPA and Spring Data annotations of different stores on the same class.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache HttpClient 5 has no setSSLSocketFactory on HttpClients.custom()
HttpClients.custom().setSSLSocketFactory() method not found
In Apache HttpClient 5 the TLS setup no longer sits on the client builder.
2 causes, each with a fixBack end
A scanner flags jackson-databind: how to upgrade it in Gradle
jackson-databind vulnerability reported by a dependency scanner
Find where the old jackson-databind comes from, then raise it.
3 causes, each with a fixBack end
Spring Boot cannot bind spring.datasource.password with Jasypt ENC() values
Failed to bind properties under 'spring.datasource.password' to java.lang.String
The binding error means Jasypt could not turn the ENC(...) value back into plain text.
3 causes, each with a fixBack end
Gradle cannot resolve spring-boot-gradle-plugin after a Spring Boot 3 upgrade
Plugin [id: 'org.springframework.boot', version: '3.0.1'] was not found in any of the following sources
Spring Boot 3 needs Java 17 or newer and a recent Gradle, and its Gradle plugin is published on the Gradle Plugin Portal.
3 causes, each with a fixBack end
bootJar cannot find the main class of a Spring Boot project
Main class name has not been configured and it could not be resolved
The Spring Boot Gradle plugin looks in the main source set's output for a class with a public static void main method.
2 causes, each with a fixBack end
Spring Boot fails at startup with an error processing a condition on an auto-configuration
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
This message only says Spring Boot failed while evaluating an auto-configuration condition.
3 causes, each with a fix