Java 无法为 XML 架构命名空间找到 Spring NamespaceHandler

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6601391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:06:51  来源:igfitidea点击:

Unable to locate Spring NamespaceHandler for XML schema namespace

javaeclipsespringtomcatservlets

提问by Bruce

I am running some servlet code in tomcat in eclipse. It's been working fine but today I get the error Unable to locate Spring NamespaceHandler for XML schema namespace. The full error looks like this:

我在 eclipse 中的 tomcat 中运行一些 servlet 代码。它一直工作正常,但今天我收到错误Unable to locate Spring NamespaceHandler for XML schema namespace。完整的错误如下所示:

SEVERE: Allocate exception for servlet RunServlet
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 [spring/dao.xml]

I've had a look at other questions regarding this error, but I don't really understand the answers.

我查看了有关此错误的其他问题,但我不太明白答案。

When I look at the target libs, I can see that spring-tx-3.0.5.RELEASE.jaris in WEB-INF/lib.

当我查看目标库时,我可以看到它spring-tx-3.0.5.RELEASE.jarWEB-INF/lib.

Can anyone help me out?

谁能帮我吗?

Thanks so much!

非常感谢!

EDIT: dao.xmlstarts:

编辑:dao.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:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

EDIT: Not sure if this is relevant, but I'm working on a mac book pro, and the latest mac update updated to Java 1.6, and I just switched over my Java preferences to 1.6.

编辑:不确定这是否相关,但我正在使用 mac book pro,最新的 mac 更新更新为 Java 1.6,我刚刚将我的 Java 首选项切换到 1.6。

EDIT: I'm also getting the following message in the Tomcat log, but I think I was getting it before and I don't think it's related, but just in case:

编辑:我还在 Tomcat 日志中收到以下消息,但我想我之前收到过它,我认为它不相关,但以防万一:

INFO: Starting Servlet Engine: Apache Tomcat/7.0.14
Jul 6, 2011 11:59:55 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/Users/bw/Documents/workspace2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/core/WEB-INF/lib/servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

EDIT: Sorry - didn't see your comments. Here's a listing of the WEB-INF.

编辑:对不起 - 没有看到您的评论。这是WEB-INF.

b-ws-macbook-pro:lib bw$ ls -ltr
total 13456
-rw-r--r--  1 bw  staff   62983 May 14 09:26 activation-1.1.jar
-rw-r--r--  1 bw  staff   53082 May 14 09:26 spring-asm-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff   60686 May 14 09:26 commons-logging-1.1.1.jar
-rw-r--r--  1 bw  staff   61379 May 14 09:26 spring-oxm-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff    4467 May 14 09:26 aopalliance-1.0.jar
-rw-r--r--  1 bw  staff  100870 May 14 09:26 spring-context-support-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff   62086 May 14 09:26 commons-pool-1.3.jar
-rw-r--r--  1 bw  staff  169752 May 14 09:26 spring-expression-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  175412 May 14 09:27 spring-webmvc-portlet-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  121757 May 14 09:27 commons-dbcp-1.2.2.jar
-rw-r--r--  1 bw  staff  321190 May 14 09:27 spring-aop-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  231922 May 14 09:27 spring-tx-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  334327 May 14 09:27 spring-orm-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  371792 May 14 09:27 mybatis-2.3.5.jar
-rw-r--r--  1 bw  staff  382442 May 14 09:27 spring-core-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  418977 May 14 09:27 spring-webmvc-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  388864 May 14 09:27 mail-1.4.jar
-rw-r--r--  1 bw  staff  395587 May 14 09:27 spring-web-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  668861 May 14 09:27 spring-context-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  555410 May 14 09:27 spring-beans-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  385712 May 14 09:27 spring-jdbc-3.0.5.RELEASE.jar
-rw-r--r--  1 bw  staff  512707 May 14 09:27 mysql-connector-java-5.0.5.jar
-rw-r--r--  1 bw  staff  610790 May 14 09:27 c3p0-0.9.1.2.jar
-rw-r--r--  1 bw  staff  391834 May 14 09:27 log4j-1.2.15.jar

EDIT: Thanks, Christian. It's weird, though, because I DON'T have that file in my jars anyway, and I do list it as provided:

编辑:谢谢,克里斯蒂安。不过,这很奇怪,因为无论如何我的 jars 中都没有那个文件,而且我确实按照提供的方式列出了它:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

I'm sure I'm missing something here..

我确定我在这里遗漏了一些东西..

EDIT: Hmm.. now Tomcat can't even find applicationContext. Something weird going on with my setup, I think.

编辑:嗯 .. 现在 Tomcat 甚至找不到applicationContext. 我想我的设置发生了一些奇怪的事情。

采纳答案by Bruce

Gah. I fixed it, but I really don't know how. I read this post ClassNotFoundException DispatcherServlet when launching Tomcat (Maven dependencies not copied to wtpwebapps)and saw that I had the same thing - a problem listed with the build in the 'markers' pane. I ran the quick fix it suggested and now everything is working again. Like I said, I hadn't touched it since a couple of days ago. Apparently it just gets confused sometimes. 6 hours later.. Thanks for your suggestions, guys.

嘎。我修复了它,但我真的不知道如何。我在启动 Tomcat 时阅读了这篇文章ClassNotFoundException DispatcherServlet(Maven 依赖项未复制到 wtpwebapps)并看到我遇到了同样的事情 - 在“标记”窗格中列出了构建问题。我运行了它建议的快速修复,现在一切都恢复正常了。就像我说的,自从几天前我就没有碰过它。显然,它有时会感到困惑。6 小时后.. 感谢您的建议,伙计们。

回答by Mark Pope

Change the namespace in dao.xml from

将 dao.xml 中的命名空间从

http://www.springframework.org/schema/tx/spring-tx-2.0.xsd

to

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

(and probably spring-beans too)

(也可能是春豆)

回答by Joseph Lust

I had this same problem from Eclipse Indigo on Kubuntu. I removed m2e and reinstalled a different version of the connector, http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/, and everything runs fine now.

我在 Kubuntu 上的 Eclipse Indigo 遇到了同样的问题。我删除了 m2e 并重新安装了不同版本的连接器http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/,现在一切正常。

回答by Alvaro

For future references:

供以后参考:

Maybe you forgot some spring-XXX dependency.

也许你忘记了一些 spring-XXX 依赖。

Por example, in maven check if you have the related dependency:

例如,在 maven 中检查您是否有相关的依赖项:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-XXX</artifactId>
    <version>${org.springframework.version}</version>
</dependency>

Regards

问候