English 中文(简体)
在春夏马举行的混凝土中利用p和实用名称空间的正确途径
原标题:Correct way to utilize p and util namespace in Spring XML Configuration

My goal is to rewrite the sessionFactory section of my xml file into the same format as all other areas in my xml file. I need to use the p-namespace to make things look consistent and neat. The problem that I ran into is using the util/p namespace.

感谢你让我赞扬这一职位。 这是我的整个Xml档案:

<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:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!-- DataSource Beans -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
    destroy-method="close"
    p:url="jdbc:hsqldb:file:database.dat;shutdown=true"
    p:driverClassName="org.hsqldb.jdbcDriver"
    p:username="sa"
    p:password="" />

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mappingResources">
        <list>
            <value>/com/bookstore/domain/Book.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
</bean>

<!-- Template Beans -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
    p:dataSource-ref="dataSource" />

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"
    p:sessionFactory-ref="sessionFactory" />


<!-- DAO Beans -->
<bean id="bookDao" class="com.bookstore.data.BookDao"
    p:hibernateTemplate-ref="hibernateTemplate" />

<bean id="accountDao" class="com.bookstore.data.AccountDao"
    init-method="createTable"
    p:jdbcTemplate-ref="jdbcTemplate" />


<!-- Service Beans -->
<bean id="bookService" class="com.bookstore.services.BookService" 
    p:bookDao-ref="bookDao" />

<bean id="purchasingService" class="com.bookstore.services.PurchasingService"
    p:bookServiceInterface-ref="bookService" 
    p:accountServiceInterface-ref="accountService" ></bean>

<bean id="accountService" class="com.bookstore.services.AccountService"
    p:accountDao-ref="accountDao" />


<!-- AOP Advice Beans -->
<bean id="loggingAdvice" class="com.bookstore.advice.LoggingAdvice" />

<bean id="performanceTimingAdvice" class="com.bookstore.advice.PerformanceTimingAdvice" />

<!-- Auto Proxy -->
<aop:aspectj-autoproxy />

 </beans>

This is what I have so far - using a combination of util:list and util:properties:

<util:list id="mappingResourcesList">
    <value>/com/bookstore/domain/Book.hbm.xml</value>
</util:list>

<util:properties id="hibernatePropertiesProps">
    <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
</util:properties>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
    p:dataSource-ref="dataSource"
    p:mappingResources-ref="mappingResourcesList"
    p:hibernateProperties-ref="hibernatePropertiesProps" />

The error message that I m getting currently pertains to the util:list, but I m equally suspicious of my util:properties as well:

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 .

What part of my util:list and util:properties must I change to get this to work?

最佳回答

What XML namespaces do p and util map to? These need to be declared with xmlns:p="..." and xmlns:util="..." somewhere within the XML element or a parent element of which they are being used.

(你再次收到的错误并非特别针对SAX,而是属于XML教区。)

For example, for using util, your XML should begin with the following:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

详情见

关于<代码>p,你还希望补充:

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

注:无一要求您使用<代码>p:和util:。 这些只是公约使用的。 您可以改写你的XML,使用a:b:,处处处——只要这些名称被界定为向相同的XML名称空间进行测绘。 (这就是为什么需要加以界定。)

问题回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签