我正在用Spring和mybatis练习来训练自己。
从昨天开始,我就试图解决这两个错误:
1)
描述资源路径位置类型cvc-Complation-type.2.4. c:匹配的通配符是严格的,但找不到元素“上下文:注释-config”的声明。 ApplicationContext.xml /Example/WebContent/WEB-INF第14行XML问题
对于这些行:
<context:component-scan base-package="Controller" />
<context:component-scan base-package="service"/>
<context:component-scan base-package="test.dao.samp"/>
<context:component-scan base-package="test.model.samp"/>
而这个:
2)
描述资源路径位置类型
schema_reference.4:无法读取架构文档“http://www.springframework.org/schema/context/spring-context-4.0.xsd”,因为 1) 找不到文档;2)文件无法阅读;3) 文档的根元素不是 。ApplicationContext.xml /Exemple/WebContent/WEB-INF line 14 XML Problem
schema\ureference.4:无法读取架构文档'http://www.springframework.org/schema/tx/spring-tx-4.0.xsd',因为1)找不到文档;2) 无法读取文档;3) 文档的根元素不是。ApplicationContext.xml/Example/WebContent/WEB-INF第51行xml问题
这是我的ApplicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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-4.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="Controller" />
<context:component-scan base-package="service"/>
<context:component-scan base-package="test.dao.samp"/>
<context:component-scan base-package="test.model.samp"/>
<bean id='dataSource'
class='org.springframework.jdbc.datasource.SimpleDriverDataSource'>
<property name='driverClass' value='org.apache.derby.jdbc.EmbeddedDriver' />
<property name='url'
value='jdbc:derby:C:\Users\XXX\IBM\rationalsdp\workspace\.metadata\.plugins\com.ibm.datatools.db2.cloudscape.driver\SAMPLE;create=true' />
<property name='username' value='admin' />
<property name='password' value='admin' />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="WEB-INF\psaIbatisConf.xml" />
</bean>
<bean id="sqlMapClient" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
<!-- TRANSACTION MANAGER -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- ANNOTATION DRIVEN TRANSACTIONS -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
我是如何理解的,错误来自错误的 xsd 声明,但我检查了很多次。
我使用的罐子都是 4.0.4 版本。
我正在使用 RAD、Websphere、spring e myBatis 和 myBatis 生成器。
编辑:
我以这种方式更改了beans标记中的版本模式:
<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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
第一个错误已经消失,但最后一个错误(第51行)仍然存在。
看看这个Contex的例子,也许可以帮助你。我使用相同的事务管理器。
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mockito="http://www.mockito.org/spring/mockito"
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.mockito.org/spring/mockito https://bitbucket.org/kubek2k/springockito/raw/tip/springockito/src/main/resources/spring/mockito.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.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<tx:annotation-driven/>
<context:component-scan base-package="cat.base.gpt.logica" />
<import resource="classpath:tip-appConfiguration.xml" />
<bean id="gptServei" class="cat.base.gpt.logica.serveis.impl.ServeiGpt">
<property name="serveiSubjecte" ref="serveiSubjecte"/>
<property name="vwGptVBasicDAO" ref="vwGptVBasicDAO" />
<property name="vwGptVExpMSDAO" ref="vwGptVExpMSDAO" />
<property name="vwGptVObjectesBasicDAO" ref = "vwGptVObjectesBasicDAO"/>
<!--
Propietat per falicilitar el filtratge cat.base.gpt.multiens
true:Recuperem tots els ens
false: filtrem per ens
-->
<property name="filtratgeEns" value="${cat.base.gpt.multiens}"/>
<qualifier type="cat.base.gpt.domini.serveis.IServeiGpt" value="gptServei" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="connexioJdbctemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg type="javax.sql.DataSource" ref="dataSource"/>
</bean>
<bean id="preparadorJdbctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg type="javax.sql.DataSource" ref="dataSource"/>
</bean>
<bean id="vwGptVBasicDAO" class="cat.base.gpt.logica.dao.impl.VwGptVBasicDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<bean id="vwGptVExpMSDAO" class="cat.base.gpt.logica.dao.impl.VwGptExpMSDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<!-- DAO referent a objectes bàsics -->
<bean id="vwGptVObjectesBasicDAO" class="cat.base.gpt.logica.dao.impl.VwGptObjecteBasicDao">
<property name="template" ref="connexioJdbctemplate" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${cat.base.gpt.driverClassName}" />
<property name="url" value="${cat.base.gpt.url}" />
<property name="username" value="${cat.base.gpt.username}"/>
<property name="password" value="${cat.base.gpt.password}"/>
</bean>
<bean id="postprocess" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:cat/base/gpt/serveis/impl/logica.properties</value>
<value>classpath*:entorn-servidor.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="false" />
</bean>
</beans>
我解决了导入 spring-tx 库的错误,正是 spring-tx-4.0.4.RELEASE。
错误地我没有检查lib文件夹中是否有jar。