做一个spring web的小项目,在spring-servlet.xml中配置了命名空间:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
其中tx是因为用到了
<!--transaction manager for scoping/controlling the transactions-->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
,
添加的库有
org.mybatis:mybatis:3.2.8
org.springframework:spring-core:4.1.6.RELEASE
org.springframework:spring-aop:4.1.6.RELEASE
org.springframework:spring-context:4.1.6.RELEASE
org.springframework:spring-beans:4.1.6.RELEASE
org.springframework:spring-expression:4.1.6.RELEASE
org.springframework:spring-web:4.1.6.RELEASE
org.springframework:spring-webmvc:4.1.6.RELEASE
org.springframework:spring-tx:4.1.6.RELEASE
org.springframework:spring-jdbc:4.1.6.RELEASE
org.springframework:spring-context-support:4.1.6.RELEASE
mysql:mysql-connector-java:5.1.35
aopalliance:aopalliance:1.0
commons-logging:commons-logging:1.2
javax.servlet:javax.servlet-api:3.1.0
ch.qos.logback:logback-classic:1.1.3
org.slf4j:jcl-over-slf4j:1.7.7
ch.qos.logback:logback-core:1.1.3
org.slf4j:slf4j-api:1.7.7
org.mybatis:mybatis-spring:1.2.2
org.apache.commons:commons-dbcp2:2.1
org.apache.commons:commons-pool2:2.3
junit:junit:4.12
org.springframework:spring-test:4.1.6.RELEASE
org.hamcrest:hamcrest-core:1.3
运行时出现错误:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: ServletContext resource [/WEB-INF/springweb-servlet.xml]
命名已经添加了tx的命名空间和schema了。
实在不明白,没有分了,这两天努力答题做点贡献,不胜感激!
------解决思路----------------------
一、百度找spring4.x的tx写法,不同版本不同写法
二、确定引入的tx解析正确
三、清楚缓存再试试