Java 发现以元素';开头的内容无效;财产';
我得到了这个错误:Java 发现以元素';开头的内容无效;财产';,java,xml,Java,Xml,我得到了这个错误: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 45 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 45; col
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 45 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 45; columnNumber: 42; cvc-complex-type.2.4.a: Invalid content was found starting with element 'property'. 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.
这是applicationContext.xml
:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<tx:annotation-driven/>
<context:component-scan base-package="com.sajjad" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:packagesToScan="com.sajjad"
p:hibernateProperties-ref="hibernateProperties" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<!-- <util:properties id="hibernateProperties" >
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</util:properties>-->
</beans>
我也为
标记得到了这个错误:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 52 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 52; columnNumber: 52; The prefix "util" for element "util:properties" is not bound.
您的
applicationContext.xml
对于util,还需要声明名称空间
xmlns:util="http://www.springframework.org/schema/util"
你可以做一些像
<util:map id="hibernateConfig" >
<entry key="hibernate.hbm2ddl.auto" value="update" />
<entry key="hibernate.show_sql" value="true" />
<!-- Other properties -->
</util:map>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
..
..
p:hibernateProperties-ref ="hibernateConfig"/>
不,它存在,o忘记添加它。您仍然有相同的问题?是的,我有相同的问题编辑我的答案以帮助您更多。
<util:map id="hibernateConfig" >
<entry key="hibernate.hbm2ddl.auto" value="update" />
<entry key="hibernate.show_sql" value="true" />
<!-- Other properties -->
</util:map>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
..
..
p:hibernateProperties-ref ="hibernateConfig"/>