Java Spring 3.0:无法为 XML 架构命名空间找到 Spring NamespaceHandler
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1937767/
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
Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace
提问by Nick Hristov
My setup is fairly simple: I have a web front-end, back-end is spring-wired.
我的设置相当简单:我有一个 Web 前端,后端是弹簧接线的。
I am using AOP to add a layer of security on my rpc services.
我正在使用 AOP 为我的 rpc 服务添加一层安全性。
It's all good, except for the fact that the web app aborts on launch:
一切都很好,除了 Web 应用程序在启动时中止:
[java] SEVERE: Context initialization failed [java] org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/aop] [java] Offending resource: ServletContext resource [/WEB-INF/gwthandler-servlet.xml]
Here is the snippet from my xml config file:
这是我的 xml 配置文件中的片段:
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:config>
<aop:aspect id="security" ref="securityAspect" >
<aop:pointcut id="securedServices" expression="@annotation(com.fb.boog.common.aspects.Secured)"/>
<aop:before method="checkSecurity" pointcut-ref="securedServices"/>
</aop:aspect>
</aop:config>
I read over the internets that it may be my classloading the core of the problem. Doubtful, since here is my WEB-INF/lib directory:
我在互联网上读到这可能是我的类加载问题的核心。值得怀疑,因为这是我的 WEB-INF/lib 目录:
./WEB-INF/lib
./WEB-INF/lib/aopalliance-alpha1.jar
./WEB-INF/lib/aspectj-1.6.6.jar
./WEB-INF/lib/commons-collections.jar
./WEB-INF/lib/commons-logging.jar
./WEB-INF/lib/ehcache-core-1.7.0.jar
./WEB-INF/lib/ejb3-persistence.jar
./WEB-INF/lib/hibernate
./WEB-INF/lib/hibernate/antlr.jar
./WEB-INF/lib/hibernate/asm.jar
./WEB-INF/lib/hibernate/bsh-2.0b1.jar
./WEB-INF/lib/hibernate/cglib.jar
./WEB-INF/lib/hibernate/dom4j.jar
./WEB-INF/lib/hibernate/freemarker.jar
./WEB-INF/lib/hibernate/hibernate-annotations.jar
./WEB-INF/lib/hibernate/hibernate-shards.jar
./WEB-INF/lib/hibernate/hibernate-tools.jar
./WEB-INF/lib/hibernate/hibernate.jar
./WEB-INF/lib/hibernate/jtidy-r8-20060801.jar
./WEB-INF/lib/jabsorb
./WEB-INF/lib/jabsorb/jabsorb-1.3.1.jar
./WEB-INF/lib/jta.jar
./WEB-INF/lib/jyaml-1.3.jar
./WEB-INF/lib/postgresql-8.4-701.jdbc4.jar
./WEB-INF/lib/sjsxp.jar
./WEB-INF/lib/spring
./WEB-INF/lib/spring/org.springframework.aop-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.asm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.aspects-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.beans-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.context-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.context.support-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.core-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.expression-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.instrument-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.instrument.tomcat-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.jdbc-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.jms-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.orm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.oxm-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.test-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.transaction-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.portlet-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.servlet-3.0.0.RELEASE.jar
./WEB-INF/lib/spring/org.springframework.web.struts-3.0.0.RELEASE.jar
./WEB-INF/lib/testng-5.11-jdk15.jar
./WEB-INF/web.xml
采纳答案by Peter Lynch
Did you try putting all your jars directly in the WEB-INF/lib
dir instead of sub-dirs of that?
您是否尝试将所有罐子直接放在WEB-INF/lib
目录中而不是子目录中?
No WEB-INF/lib/spring/org.springframework.aop-3.0.0.RELEASE.jar
, just WEB-INF/lib/org.springframework.aop-3.0.0.RELEASE.jar
不WEB-INF/lib/spring/org.springframework.aop-3.0.0.RELEASE.jar
,只是WEB-INF/lib/org.springframework.aop-3.0.0.RELEASE.jar
Same with the rest of the jars.
其余的罐子也一样。
回答by delfuego
What IDE (if any) are you using? Does this happen when you're working within an IDE, or only on deployment? If it's deployment, it might be because whatever mechanism of deployment you use -- maven-assembly making a single JAR with dependencies is a known culprit-- is collapsing all your JARs into a single directory and the Spring schema and handler files are overwriting each other.
您使用的是什么 IDE(如果有)?当您在 IDE 中工作时或仅在部署时会发生这种情况吗?如果是部署,则可能是因为您使用的任何部署机制——maven-assembly 制作具有依赖项的单个 JAR 是一个已知的罪魁祸首——正在将所有 JAR 折叠到一个目录中,并且 Spring 模式和处理程序文件正在覆盖每个其他。
回答by wuntee
In case someone else runs into this problem, I just did using Eclipse; running the project via the right click action. This error occurred in the J2EE view, but did NOT occur in the Java view. Not sure - assuming something with adding libraries to the correct 'lib' directory.
如果其他人遇到这个问题,我只是使用 Eclipse;通过右键单击操作运行项目。此错误发生在 J2EE 视图中,但未发生在 Java 视图中。不确定 - 假设将库添加到正确的“lib”目录。
I am also using a Maven project, allowing m2eclipse to manage dependancies.
我也在使用 Maven 项目,允许 m2eclipse 管理依赖项。
回答by Francisco Villa Ramos
I have the same problem with spring 3.0.2 and spring-beans-3.0.xsd.
我对 spring 3.0.2 和 spring-beans-3.0.xsd 有同样的问题。
My solution:
我的解决方案:
Create a file META-INF/spring.schemas in the source folder and copy all necesary definitions. Create spring.handlers too.
在源文件夹中创建一个文件 META-INF/spring.schemas 并复制所有必要的定义。也创建 spring.handlers。
I think that the class PluggableSchemaResolver is not working correctly.
我认为 PluggableSchemaResolver 类工作不正常。
from the javadoc:
来自 javadoc:
"By default, this class will look for mapping files in the classpath using the pattern: META-INF/spring.schemas allowing for multiple files to exist on the classpath at any one time."
“默认情况下,此类将使用以下模式在类路径中查找映射文件:META-INF/spring.schemas 允许在任何时候类路径上存在多个文件。”
but in my case, this class only read the first spring.schemas finded.
但就我而言,这个类只读取了找到的第一个 spring.schemas。
Grettings. pacovr
问候。帕科夫
回答by Kevin
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
I ran into a similar problem using the maven-shade-plugin. I found the solution to my problems in their example page above.
我使用 maven-shade-plugin 遇到了类似的问题。我在上面的示例页面中找到了解决我的问题的方法。
回答by Johan
回答by skywind
I ran into a similar error, but refering to Spring Webflow in a newly created Roo project. The solution for me turned out to be (Project) / right-click / Maven / Enable Maven Dependencies (followed by some restarts and republishes to Tomcat).
我遇到了类似的错误,但在新创建的 Roo 项目中引用了 Spring Webflow。我的解决方案原来是(项目)/右键单击/Maven/启用Maven依赖项(然后重新启动并重新发布到Tomcat)。
It appeared that STS or m2Eclipse was failing to push all the spring webflow jars into the web app lib directory. I'm not sure why. But enabling maven dependency handling and then rebuilding seemed to fix the problem; the webflow jars finally get published and thus it can find the schema namespace references.
似乎 STS 或 m2Eclipse 未能将所有 spring webflow jar 推送到 web 应用程序 lib 目录中。我不知道为什么。但是启用 maven 依赖处理然后重建似乎可以解决问题;webflow jars 最终被发布,因此它可以找到架构命名空间引用。
I investigated this by exploring the tomcat directory that the web app was published to, clicking into WEB-INF/lib/ while it was running and noticing that it was missing webflow jar files.
我通过浏览 web 应用程序发布到的 tomcat 目录来调查这个问题,在它运行时单击 WEB-INF/lib/ 并注意到它缺少 webflow jar 文件。
回答by javasun
This trick worked for me too: In Eclipse right-click on the project and then Maven > Update Dependencies.
这个技巧对我也有用:在 Eclipse 中右键单击项目,然后 Maven > 更新依赖项。
回答by panksdmz
If using mvn
, check that you have the correct scope (if you have that defined) in your pom.xml
. I once had it incorrectly set to testbut needed it for runtime.
如果使用mvn
,请检查您的pom.xml
. 我曾经错误地将它设置为test但需要它用于运行时。
回答by xgMz
Encountered this error while using maven-shade-plugin, the solution was including:
使用 maven-shade-plugin 时遇到此错误,解决方法包括:
META-INF/spring.schemas
META-INF/spring.schemas
and
和
META-INF/spring.handlers
META-INF/spring.handlers
transformers in the maven-shade-plugin when building...
构建时 maven-shade-plugin 中的转换器...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
(积分:避免在单个 jar 中合并多个 spring 依赖项时 spring.handlers/spring.schemas 被覆盖的想法)