We Are Going To Discuss About Spring-boot: required a bean named ‘entityManagerFactory’ that could not be found. So lets Start this Java Article.
Spring-boot: required a bean named ‘entityManagerFactory’ that could not be found
- Spring-boot: required a bean named 'entityManagerFactory' that could not be found
I was getting error message like-
required a bean named 'entityManagerFactory' that could not be found.
After lot of googling solve this problem.
I set manual configuration for JPA. - Spring-boot: required a bean named 'entityManagerFactory' that could not be found
I was getting error message like-
required a bean named 'entityManagerFactory' that could not be found.
After lot of googling solve this problem.
I set manual configuration for JPA.
Solution 1
I was getting error message like-
required a bean named ‘entityManagerFactory‘ that could not be found.
After lot of googling solve this problem.
I set manual configuration for JPA.
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
return sessionFactory;
}
but JPA by default search sessionFactory by name ‘entityManagerFactory‘
so change my code as:
@Bean(name="entityManagerFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
return sessionFactory;
}
Original Author Istiaque Hossain Of This Content
Solution 2
For me, I’ve forgotten to remove DataSourceAutoConfiguration.class
from exclusions.
So this:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
// Main class definition
Should be:
@SpringBootApplication()
// Main class definition
Original Author Abdulrahman Hashem Of This Content
Solution 3
Run into same issue when trying to connect spring boot to mysql database.
What saved me was adding correct version of hibernate-core to my pom file.
From hibernate onwards 5.2.0. hibernate-entitymanager is no longer needed. Hibernate-core 5.2.0 have problem with Spring Data JPA while process collection.Hibernate-core 5.2.1
and above is ok with Spring Data JPA if you are using Spring Data JPA.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version> 5.2.1.Final</version>
</dependency>
Original Author user9347049 Of This Content
Solution 4
in our case was working fine but not for tests with @WebMvcTest
Took a while to find out but issue was:
@SpringBootApplication
@ComponentScan({"com.givenproject"})
@EntityScan("com.givenproject")
@EnableJpaRepositories("com.givenproject")
@Configuration
public class Application {
instead do:
@SpringBootApplication
@Configuration
public class Application {
and
@Configuration
@ComponentScan({"com.givenproject"})
@EntityScan(basePackages = "com.givenproject")
@EnableJpaRepositories(basePackages = "com.givenproject")
public class DataConfig {
}
Original Author dpalacio Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.