title: Issue with Spring Hibernate PostgreSQL configuration
body: <p>I am getting various issues with configuration of spring hibernate and postgresql. I try to resolve one issue and i get some different issue. 
  I am using spring 3.1.0 release version and hibernate 4.1.4.Final
  I am getting error BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext</p>
  
  <p>and my web.xml is </p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/dispatcher-servlet.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And my dispatcher-servlet is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  &lt;mvc:annotation-driven&gt; &lt;/mvc:annotation-driven&gt;
  &lt;context:component-scan base-package="com.max.ade.common.model" /&gt;
  &lt;context:component-scan base-package="com.max.ade.daoImpl" /&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
      &lt;property name="url" value="jdbc:postgresql://localhost:5432/TestUserDB" /&gt;
      &lt;property name="username" value="postgres" /&gt;
      &lt;property name="password" value="root123" /&gt;
  &lt;/bean&gt;
  &lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean"&gt;
  
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
      &lt;!-- Scan packages for annotated entities --&gt;
      &lt;property name="packagesToScan" value="com.max.ade.common.model" /&gt;
  &lt;/bean&gt;
  &lt;!-- Transaction support beans --&gt;
  &lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"&gt;&lt;/tx:annotation-  driven&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>And after issue resolving, above is my file structure for dispatcher-servlet.xml. 
  Are configuration things work differently with hibernate 3.6.4 and hibernate 4.1.4 beside issue mentioned (BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext)</p>
  
  <p>Any concrete pointer will be great help. </p>
  
  <p>Thanks. </p>