Check out the documentation for the @EnableJpaRepositories
annotation.
In the Optional Element Summary, you'll find:
String entityManagerFactoryRef
Configures the name of the EntityManagerFactory bean definition to be used to create repositories discovered through this annotation.
Scrolling down the page to the details section, you'll see:
entityManagerFactoryRef
public abstract String entityManagerFactoryRef
Configures the name of the EntityManagerFactory bean definition to be used to create repositories discovered through this annotation. Defaults to
entityManagerFactory
.Returns:
Default: "entityManagerFactory"
So, this "conventional" default configuration is specified by the @EnableJpaRepositories
annotation itself.
When encountering the error message Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument;
, it indicates that Spring cannot find a bean named 'entityManagerFactory' to inject into a constructor argument.
To resolve this error, follow these steps:
@Configuration
or @Component
to make it discoverable by Spring.1. The exception indicates that there is no bean with the name entityManagerFactory
. Place a debug point in the entityManagerFactory
method of org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration
class and check why the bean is not getting initialized.
Oh, from the discussion, I've concluded that the mentioned issue is likely due to older Hibernate dependencies. Additionally, ensure that the @Id
annotation imported for all your entities is from javax.persistence.id
.