Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'

I'm getting below error while running my Springboot application

Error creating bean with name 'userRepo' defined in defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'

package <mypackage>;

import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;


public interface UserRepo extends JpaRepository<User,Long>{
    Optional<User> findByEmail(String email);
}

I'm using Java 17, Spring-boot 3.1.2, spring-boot-starter-data-jpa and spring-boot-starter-security

I've tried to check if my database server is running & correctly configured in application.properties file but i've not found any problem there

like image 784
Janak Vaghasiya Avatar asked Sep 01 '25 01:09

Janak Vaghasiya


1 Answers

I also encountered this issue when I tried to upgrade from Springboot 2.x.x to 3.x.x. Finally figured out it is due to wrongly defined naming strategy. In my case I updated below line in my application.yml file and solved the issue.

Previously I had

physicalNamingStrategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

Then I changed it to

physicalNamingStrategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
like image 76
SNJ Avatar answered Sep 03 '25 15:09

SNJ