我注意到关于Spring XML模式的一个奇怪的问题。

我有一个使用spring框架的独立Java应用程序。只要我在Eclipse中运行此应用程序,我就不会遇到任何问题。但是,当我将此文件打包为jar文件(如此link中所述)并执行jar时,出现以下异常:

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)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1416)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)


我在applicationContext.xml中有以下条目,并且在eclipse中可以正常工作:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.1.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">


任何帮助深表感谢。

我什至尝试将http://www.springframework.org/schema/tx/spring-tx-3.1.xsd更改为classpath:/org/springframework/transaction/config/spring-tx-3.1.xsd,但这没有帮助。

最佳答案

看起来您的应用程序包含一些jar,例如spring-core-3.1.x(因为正在使用其类),但是缺少了spring-tx-3.1.x.RELEASE.jar(用于保存Spring Transaction类的类)。

09-11 06:30
查看更多