您的位置:首页 > 移动开发

spring applicationContext.xml namespace 异常问题

2012-08-08 11:14 387 查看
本地开发环境用eclipse,用maven管理

一切正常

将程序部署到linux服务器上时,报出以下错误

Exception in thread "main" 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: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)

at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)

1. 网上有人说是缺少了org.springframework.transaction这个包,但我本地也没有,可以运行啊,应该不是这个问题

2.把部署程序在windows上单独的文件夹中运行了一下,用bat 脚本 启动,正常没问题

3.那会是什么问题呢?实在想不到,就试着网上说的办法 ,在linux下加了org.springframework.transaction,果然没问题了

测试:

spring-tx-3.1.1.RELEASE.jar

org.springframework.transaction-3.1.1.RELEASE.jar

这两个包其实是一样的

1.只有spring-tx-3.1.1.RELEASE.jar ,报上面提到的错误

2.只有org.springframework.transaction-3.1.1.RELEASE.jar,报

java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DataSourceTransactionManager

3.两个都有,没问题

结论:

确认如错误所说应该是命名的问题,但暂时还没找到是哪里的问题

附上applicationContext.xml

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

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

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

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

xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<context:property-placeholder location="classpath*:jdbc.properties" />

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

<property name="driverClass" value="${jdbc.driver}" />

<property name="jdbcUrl" value="${jdbc.url}" />

<property name="user" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

<property name="minPoolSize" value="1" />

<property name="maxPoolSize" value="10" />

<property name="maxIdleTime" value="1800" />

<property name="initialPoolSize" value="1" />

<property name="checkoutTimeout" value="60000" />

<property name="debugUnreturnedConnectionStackTraces" value="true" />

<property name="unreturnedConnectionTimeout" value="120" />

</bean>

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />

</bean>

<!-- enable autowire -->

<context:annotation-config />

<!-- enable transaction demarcation with annotations -->

<tx:annotation-driven />

<!-- define the SqlSessionFactory -->

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="classpath:mybatis-config.xml" />

<property name="typeAliasesPackage" value="zzz" />

</bean>

<!-- scan for mappers and let them be autowired -->

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="yyyy" />

</bean>

<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

</beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐