2014-08-27 134 views
0

enter image description here使用Spring + Hibernate的MVC

我一直在使用Spring + Hibernate的MVC啓動Web應用程序。我創建了所有文件。當我調試我的應用程序時有一些問題。 在這裏我附上了web.xml,test-servlet.xml的代碼和我添加了錯誤行 任何一個幫助我PLZ在這?

錯誤:org.springframework.beans.factory.beandefinitionstoreexception 意外的異常解析XML文檔從文件 /WEBINF/config/test.servlet.xml

測試的servlet

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

    <context:property-placeholder location="classpath:resources/database.properties" /> 

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" /> 

    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="${database.driver}" /> 
    <property name="url" value="${database.url}" /> 
    <property name="username" value="${database.user}" /> 
    <property name="password" value="${database.password}" /> 
    </bean> 

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="annotatedClasses"> 
     <list> 
     <value>model.Register</value> 
     </list> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
     <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
     <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
     <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> 
     </props> 
    </property> 
    </bean> 

    <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

</beans> 

test-servlet

web.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" 
    version="3.0"> 

    <display-name>SpringHibernateMVC</display-name> 

    <servlet> 
    <servlet-name>test</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/config/test-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>test</servlet-name> 
    <url-pattern>*.html</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 

</web-app> 

web.xml

+0

我們展示的堆棧跟蹤被列入鏈接的圖像中的錯誤信息 – 2014-08-27 09:27:42

+0

。我修正了一些格式.. – nfechner 2014-08-27 09:33:07

+0

你爲什麼還原了我的編輯? – nfechner 2014-08-27 09:40:13

回答

0

從項目文件夾像我看得出來,你缺少資源文件夾。

請確保您擁有您在 test.servlet.xml中提到的resources/database.properties文件。

<context:property-placeholder location="classpath:resources/database.properties" />