2012-08-22 107 views
0

我收到春季休眠和postgresql配置的各種問題。我嘗試解決一個問題,並得到一些不同的問題。 我使用彈簧3.1.0發行版本和休眠4.1.4.Final 我得到錯誤的beanfactory未初始化或已關閉 - 通過調用在ApplicationContext春季Hibernate PostgreSQL配置問題

訪問豆之前「刷新」和我的web.xml是

<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"> 
<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>*.htm</url-pattern> 
</servlet-mapping> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
</context-param> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
</web-app> 

我的調度員的servlet:

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
<mvc:annotation-driven> </mvc:annotation-driven> 
<context:component-scan base-package="com.max.ade.common.model" /> 
<context:component-scan base-package="com.max.ade.daoImpl" /> 
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName" value="org.postgresql.Driver" /> 
    <property name="url" value="jdbc:postgresql://localhost:5432/TestUserDB" /> 
    <property name="username" value="postgres" /> 
    <property name="password" value="root123" /> 
</bean> 
<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix"> 
     <value>/WEB-INF/pages/</value> 
    </property> 
    <property name="suffix"> 
     <value>.jsp</value> 
    </property> 
</bean> 
<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate4.annotation.AnnotationSessionFactoryBean"> 

    <property name="dataSource" ref="dataSource" /> 
    <property name="configLocation" value="classpath:hibernate.cfg.xml" /> 
    <!-- Scan packages for annotated entities --> 
    <property name="packagesToScan" value="com.max.ade.common.model" /> 
</bean> 
<!-- Transaction support beans --> 
<bean id="transactionManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
</bean> 
<tx:annotation-driven transaction-manager="transactionManager"></tx:annotation- driven> 
</beans> 

及發行後解決,以上是我對調度員servlet.xml文件結構。 是配置事情休眠3.6.4不同的方式工作和休眠提到的問題,旁邊4.1.4(Bean工廠未初始化或已關閉 - 呼叫通過ApplicationContext的訪問之前豆「刷新」)

任何具體的指針將是很大的幫助。

謝謝。

回答

2

好像你是混合休眠3和休眠4,

嘗試改變這種

class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 

這個

class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 

問候