2015-03-05 4 views
0

Я получил эту ошибку:Invalid контент был обнаружен, начиная с элемента 'свойства'

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> 

И web.xml файл:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" `xsi:schemaLocation="http://java.sun.com/xml/ns/javaee` 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">` 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet> 
     <servlet-name>Faces Servlet</servlet-name> 
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.xhtm</url-pattern> 
    </servlet-mapping> 
    <servlet-mapping> 
     <servlet-name>Faces Servlet</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

Я получил это ошибка для <util> бирка тоже:

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. 

ответ

2

Вы пропускаете закрывающий тег </beans> здесь в вашем 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"/> 
+0

Нет, он существует, о забыли добавить его. –

+0

И у вас все еще такая же проблема? –

+0

Да, у меня такая же проблема –

Смежные вопросы