title: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory'
body: <p>I am using spring and hibernate for configuration with mysql db.</p>
  
  <p>My we.xml file has following code :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;WEB-INF/classes/applicationcontext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My applicationcontext.xml file has following imports :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  &lt;beans default-autowire="autodetect"&gt;
    &lt;import resource="spring-config/spring-common-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-db-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-dao-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-processor-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-security-processor-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-service-applicationContext.xml"/&gt;
    &lt;import resource="spring-config/spring-security-service-applicationContext.xml"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>My spring-db-applicationContext.xml has following code :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  &lt;beans default-autowire="autodetect"&gt;
  
  &lt;!-- Hibernate session factory --&gt;
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;constructor-arg index="0"&gt;
              &lt;value&gt;${driverClassName}&lt;/value&gt;
          &lt;/constructor-arg&gt;
          &lt;constructor-arg index="1"&gt;
              &lt;value&gt;${url}&lt;/value&gt;
          &lt;/constructor-arg&gt;
          &lt;constructor-arg index="2"&gt;
              &lt;value&gt;${username}&lt;/value&gt;
          &lt;/constructor-arg&gt;
          &lt;constructor-arg index="3"&gt;
              &lt;value&gt;${password}&lt;/value&gt;
          &lt;/constructor-arg&gt;
  
      &lt;/bean&gt;
  
      &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;
          &lt;property name="sessionFactory"&gt;
              &lt;ref bean="sessionFactory"/&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource"&gt;
              &lt;ref bean="dataSource"/&gt;
          &lt;/property&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;WEB-INF/classes/hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property  name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
  
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;!--&lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;--&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory"&gt;
              &lt;ref bean="sessionFactory"/&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"&gt;
          &lt;property name="transactionManager" ref="transactionManager"/&gt;
          &lt;property name="transactionAttributeSource"&gt;
              &lt;value&gt; com.sufalam.mailserver.business.service.IUserProcessor.*=PROPAGATION_REQUIRED,-java.lang.Exception
              &lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
   &lt;/beans&gt;
  </code></pre>
  
  <p>I have included appropriate lib. Now at the time of running the project, i am getting following error :</p>
  
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionFactory' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Unsatisfied dependency expressed through bean property 'eventListeners': : Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1141)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1034)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:526)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:730)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:387)
          at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:270)
          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
          at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
          at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
          at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
          at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
          at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
          at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
          at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
          at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
          at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
          at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
          at org.apache.catalina.core.StandardService.start(StandardService.java:516)
          at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in URL [jndi:/localhost/MailServerV2/WEB-INF/classes/spring-config/spring-db-applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1299)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1061)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:289)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:286)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:807)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:735)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:666)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1126)
          ... 37 more
  Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject
          at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:157)
          at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:109)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1397)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:243)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
          at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
          ... 50 more
  </code></pre>
  
  <p>Can anybody have any solutions, why my sessionFactory bean is giving error ?</p>
  
  <p>Thanks in advance...</p>