spring 5.+jpa configuration class error.
December 20, 2018 5:53:01 PM org.springframework.web.servlet.DispatcherServlet initServletBean
Seriously : Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘studentRepository’: Cannot create inner bean ‘(inner bean)#69ecc373’ of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property ‘entityManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘(inner bean)#69ecc373’: Cannot resolve reference to bean ‘entityManagerFactory’ while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘entityManagerFactory’ available
One of the reasons for this is the incorrect method name in the configuration class.
@Bean
public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean()
{
//EntityManagerFactory
LocalContainerEntityManagerFactoryBean bean=new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(dataSource());
bean.setPackagesToScan(new String[] {"com.jpa.demo"});
bean.setJpaVendorAdapter(jpaVendorAdapter());
return bean;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory()
{
//EntityManagerFactory
LocalContainerEntityManagerFactoryBean bean=new LocalContainerEntityManagerFactoryBean();
bean.setDataSource(dataSource());
bean.setPackagesToScan(new String[] {"com.jpa.demo"});
bean.setJpaVendorAdapter(jpaVendorAdapter());
return bean;
}
Similar Posts:
- mybatis: Property ‘configuration’ and ‘configLocation’ can not specified with together
- Spring Error: Bean instantiation via factory method failed StackOverflowError
- Property ‘dataSource’ threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
- Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘userDaoImpl’ defined in file
- Springboot import JPA Error: a bean named ‘entityManagerFactory’ that could not be found
- [Solved] Springboot startup error: org.springframework.beans.factory.unsatisfieddependenceexception…
- How to Solve the login error of Spring + Shiro CacheManager
- Spring cloud consumer feign injection error [How to Solve]
- [Solved] Java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
- [Solved] SpringbootExpection 1: Error creating bean with name ‘xxxImpl’: Unsatisfied dependency expressed through field