我注意到 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 类的那个)。
关于java - Spring XML 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11864877/