在Spring XML配置中使用p和util命名空间的正确方法

我的目标是将xml文件的sessionFactory部分重写为与xml文件中所有其他区域相同的格式。 我需要使用p命名空间来使事物看起来一致和整洁。 我遇到的问题是使用util / p命名空间。

感谢您让我编辑此post。 这是我的整个xml文件:

       /com/bookstore/domain/Book.hbm.xml     org.hibernate.dialect.HSQLDialect update                    

这是我到目前为止 – 使用util:list和util:properties的组合:

  /com/bookstore/domain/Book.hbm.xml   org.hibernate.dialect.HSQLDialect update   

我目前收到的错误消息属于util:列表,但我同样怀疑我的util:属性:

 Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 22 in XML document from class path resource [application.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'util:list'. 

我的util:list和util:属性的哪一部分必须更改才能使其工作?

putil映射到哪些XML命名空间? 这些需要使用xmlns:p="..."声明xmlns:p="..."xmlns:util="..."在XML元素中的某个位置或者正在使用它们的父元素。

(您收到的错误并非特定于SAX,而是XML解析的通用。)

例如,对于使用util ,您的XML应该从以下开始:

  

有关其他详细信息,请访问http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/xsd-config.html#xsd-config-body-schemas-util 。

对于p ,您还需要添加:

 xmlns:p="http://www.springframework.org/schema/p" 

请注意,没有任何要求您使用p:util: . 这些只是按惯例使用。 您可以重写XML以使用a:b:无处不在 – 只要它们被定义为映射到相同的XML命名空间。 (这就是他们需要定义的原因。)

您在xsi:schemaLocation中缺少以下条目: http : //www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd

把它们放在你的XML中,你应该很好。