我的目标是将xml文件的sessionFactory部分重写为与xml文件中所有其他区域相同的格式.我需要使用p命名空间来使事物看起来一致和整洁.我遇到的问题是使用util/p命名空间.
感谢您让我编辑此帖子.这是我的整个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>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止 - 使用util:list和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" />
Run Code Online (Sandbox Code Playgroud)
我目前收到的错误消息属于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'.
Run Code Online (Sandbox Code Playgroud)
我的util:list和util:属性的哪一部分必须更改才能使其工作?
zie*_*mer 36
XML命名空间的作用p和util映射到哪些?这些都需要与声明xmlns:p="..."和xmlns:util="..."XML元素或其中正在使用它们父元素中的某处.
(您收到的错误并非特定于SAX,而是XML解析的通用.)
例如,对于使用util,您的XML应该从以下开始:
<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">
Run Code Online (Sandbox Code Playgroud)
对于p,您还需要添加:
xmlns:p="http://www.springframework.org/schema/p"
Run Code Online (Sandbox Code Playgroud)
请注意,没有任何要求您使用p:和util:.这些只是按惯例使用.你可以重写你的XML使用a:,并b:为它们定义映射到相同的XML命名空间,只要-无处不在.(这就是他们需要定义的原因.)
| 归档时间: |
|
| 查看次数: |
79724 次 |
| 最近记录: |