Home  >  Forum  >  Spring
Post New Query

Caused by: org.springframework.beans.factory. NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available



Asked on November 10, 2017
Hi, I am creating application using spring and hibernate.  I am using Java 9 and Spring 5.0.1. While starting server, there is following error in console.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1205)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367)
... 62 more



Replied on November 15, 2017
You need to create bean with name entityManagerFactory. For example.

JavaConfig 

@Bean(name="entityManagerFactory")
public LocalContainerEntityManagerFactoryBean getEntityManagerFactoryBean() {
    LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean();
         --------
         --------
    return lcemfb;
}

XML Configuration

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
     ----------
     ----------
</bean>


Write Answer




©2019 concretepage.com | Privacy Policy | Contact Us