简体   繁体   English

在我的Spring应用程序中配置休眠问题

[英]Issue configuring hibernate in my Spring Application

I was configuring hibernate on my Spring application and get following errors on my servlet-context file. 我在Spring应用程序上配置了休眠模式,并在servlet上下文文件中出现以下错误。

What have I messed up with the xml files?? 我把xml文件弄糟了吗?

Error is as follows: 错误如下:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 38 in XML document from ServletContext resource [/WEB-INF/servlet-context.xml] is invalid; org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自ServletContext资源[/WEB-INF/servlet-context.xml]的XML文档中的第38行无效; nested exception is org.xml.sax.SAXParseException; 嵌套的异常是org.xml.sax.SAXParseException; lineNumber: 38; lineNumber:38; columnNumber: 109; columnNumber:109; cvc-complex-type.2.4.a: Invalid content was found starting with element 'bean'. cvc-complex-type.2.4.a:发现无效的内容(从元素“ bean”开始)。 One of '{" http://www.springframework.org/schema/beans ":import, " http://www.springframework.org/schema/beans ":alias, " http://www.springframework.org/schema/beans ":bean, WC[##other:" http://www.springframework.org/schema/beans "], " http://www.springframework.org/schema/beans ":beans}' is expected. 其中一个“{” http://www.springframework.org/schema/beans “:进口,” http://www.springframework.org/schema/beans “:别名” http://www.springframework.org / schema / beans “:bean,WC [## other:” http://www.springframework.org/schema/beans “],” http://www.springframework.org/schema/beans“:beans }'是期待。

My Servlet-context.xml 我的Servlet-context.xml

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

<!-- DispatcherServlet Context: defines this servlet's request-processing 
    infrastructure -->

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory -->
<!-- <resources mapping="/resources/**" location="/images/" /> -->

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory -->
<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/jsp/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<beans:import resource="classpath:/WEB-INF/controllers.xml" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="/WEB-INF/jdbc.properties" >
    </bean>

<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}">
</bean>


<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${jdbc.dialect}</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans:beans>

You start off using the namespace prefix 您开始使用名称空间前缀

<beans:bean...

and

<beans:property...

but then you stop 但是你停下来

<bean...

and

<property...

Why? 为什么? Any element that is part of the beans namespace needs to be prefixed with beans . 属于beans名称空间的任何元素都必须以beans作为前缀。

Alternatively, make beans your default namespace so that you don't have to prefix all the elements that belong to it. 或者,将beans 设置为默认名称空间,这样您就不必在属于它的所有元素之前添加前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM