title: BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource
body: <p>Im using hibernate 3.2.7 and spring 3.2.8. The error is ***</p>
  
  <blockquote>
    <p>**": Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of
    init method failed; nested exception is java.io.FileNotFoundException:
    ServletContext resource [/resources/hibernate.cfg.xml] cannot be
    resolved to URL because it does not exist".</p>
  </blockquote>
  
  <hr>
  
  <p>I try to put hibernate.cfg.xml in src, in webinf and classpath: , but it still dont find it.This is my error stack trace:</p>
  
  <pre><code>&gt; org.springframework.beans.factory.BeanCreationException: Error
  &gt; creating bean with name 'sessionFactory' defined in ServletContext
  &gt; resource [/WEB-INF/spring-servlet.xml]: Invocation of init method
  &gt; failed; nested exception is java.io.FileNotFoundException:
  &gt; ServletContext resource [/resources/hibernate.cfg.xml] cannot be
  &gt; resolved to URL because it does not exist     at
  &gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
  &gt;   at
  &gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
  &gt;   at
  &gt; org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  &gt;   at
  &gt; org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
  &gt;   at
  &gt; org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  &gt;   at
  &gt; org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
  &gt;   at
  &gt; org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  &gt;   at
  &gt; org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
  &gt;   at
  &gt; org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  &gt;   at
  &gt; org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  &gt;   at
  &gt; org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
  &gt;   at
  &gt; org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
  &gt;   at
  &gt; org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
  &gt;   at
  &gt; org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
  &gt;   at
  &gt; org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
  &gt;   at
  &gt; org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  &gt;   at javax.servlet.GenericServlet.init(GenericServlet.java:158)   at
  &gt; org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
  &gt;   at
  &gt; org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
  &gt;   at
  &gt; org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
  &gt;   at
  &gt; org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
  &gt;   at
  &gt; org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
  &gt;   at
  &gt; org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  &gt;   at
  &gt; org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
  &gt;   at
  &gt; org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
  &gt;   at
  &gt; org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
  &gt;   at
  &gt; org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:670)
  &gt;   at
  &gt; org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1839)
  &gt;   at
  &gt; java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
  &gt;   at java.util.concurrent.FutureTask.run(FutureTask.java:262)     at
  &gt; java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  &gt;   at
  &gt; java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  &gt;   at java.lang.Thread.run(Thread.java:745) Caused by:
  &gt; java.io.FileNotFoundException: ServletContext resource
  &gt; [/resources/hibernate.cfg.xml] cannot be resolved to URL because it
  &gt; does not exist    at
  &gt; org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:154)
  &gt;   at
  &gt; org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBe
  </code></pre>
  
  <p>My spring-servlet is:</p>
  
  <blockquote>
    <p>
        </p>
  </blockquote>
  
  <pre><code>&lt;bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
    &lt;property name="prefix"&gt;
      &lt;value&gt;/&lt;/value&gt;
    &lt;/property&gt;
    &lt;property name="suffix"&gt;
      &lt;value&gt;.xhtml&lt;/value&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/jdbc.properties" /&gt;
  
  &lt;bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
      p:driverClassName="${jdbc.driverClassName}"
      p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
      p:password="${jdbc.password}" /&gt;
  
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="configLocation"&gt;
      &lt;value&gt;resources/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;${jdbc.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.connection.SetBigStringTryClob"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.batch_size"&gt;0&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.batch_size"&gt;0&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
  
      &lt;!-- one of the properties available; the maximum file size in bytes --&gt;
      &lt;property name="maxUploadSize" value="10000000" /&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven /&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>
  ></p>