被这个问题折磨着很久:参考: http://have23.iteye.com/blog/1340777

(cfx 与 spring 整合的时候出现的问题:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]
Offending resource: ServletContext resource [/WEB-INF/spring.xml]

Key Words

Spring 3.0

Apache CXF 2.X.X

昨日,在原本应用中添加了关于webService的调用,使用了Apache CXF 框架,并将其集成到了Spring中。

当时集成时,使用了如下的jar包(Spring2.5.5.JPG)

加入CXF的相关jar包


 然后将WebService客户端集成到Spring中,代码类似于:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:jaxws="http://cxf.apache.org/jaxws"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
  8. <jaxws:client id="helloClient"
  9. serviceClass="demo.spring.HelloWorld"
  10. address="http://localhost:9002/HelloWorld" />
  11. </beans>

然后在Myeclipse 8.5上进行了测试,运行通过。

然后通过Fat jar打成jar包进行发布。对,这不是一个web应用。

到了实际部署环境,刚运行就出现:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-2.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

出现这个错。我的第一判断是jar有冲突。你懂的

于是,我从早上11点到下午5点,来解决这个jar包冲突的问题,做了一下的工作

1.从Spring2.5.5 换到Spring.3.0.5

2.将CXF2.3.1换到CXF2.5.1

最终的结果是:蛋都碎了。。。

而且还出现了新的问题:

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://cxf.apache.org/schema/jaxws.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

终于意识到,不是jar包的问题。而是SAXParse没有正常工作。于是去网上转了一圈,有如下结果

http://stackoverflow.com/questions/1937767/spring-3-0-unable-to-locate-spring-namespacehandler-for-xml-schema-namespace

“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.”

我英文一般的很,这段话大概的意思就是

使用maven-assembly 插件压缩的all your jars到一个单一目录,并且Spring schema and handler files互相覆盖。

可惜,我没有使用maven。Spring schema and handler files 是什么

Spring步入到3.0后,出现了一些显著的变化就是没有提供spring.jar了,而采用了不同功能的jar

而几乎每个jar包中都存在

这就是导致出现

Unable to locate Spring NamespaceHandler for XML schema namespace的问题。

接下来,你可以参考

http://stackoverflow.com/questions/3650252/problem-starting-spring-application-from-java

你可以选择手工合并所有的spring.handlers与spring.schemas,或者和我一样换回到Spring 2.5,并将cxf2.x.x.jar中的这两个文件重新命名,然后不使用Spring集成,先让程序跑起来不影响业务。

参考

https://jira.springsource.org/browse/SPR-8368

这里面说的更加详细一些

With the splitting of Spring Framework into multiple jar files in v3.0, there are now several files named "META-INF/spring.handlers", "spring.schemas" and "spring.tooling". This is not a problem when running in a normal servlet container, but poses problems when e.g. creating an executable JAR file from a webapp using an embedded web server such as Jetty, or running GWT in "Dev Mode", which uses a custom class loader.

The workaround is to construct your own "custom" version of these three files, merging all the copies into one like so:

//IOUtils and FileUtils come from Apache Commons IOfor(String s : new String[] {"spring.schemas", "spring.handlers", "spring.tooling"}) {
Enumeration<?> e = Test.class.getClassLoader().getResources("META-INF/"+s);
StringBuilder out = new StringBuilder();while(e.hasMoreElements()) { URL u = (URL) e.nextElement(); out.append(IOUtils.toString(u.openStream())).append("\n"); }
File outf = new File(s);
FileUtils.writeStringToFile(outf, out.toString(), "UTF-8");
}

However, the proper fix would be to use a different file-name for each instance of the schemas/handlers/tooling files. For example, inside "org.springframework.aop-3.0.5.RELEASE.jar/META-INF" you would find "spring-aop.schemas", "spring-aop.handlers" and "spring-aop.tooling".

I'm afraid I'm not sufficiently up-to-speed with the Spring code-base to give you a patch to do this, however a brief investigation shows that "spring.handlers" and "spring.schemas" are specified in org.springframework.beans.factory.xml.PluggableSchemaResolver and DefaultNamespaceHandlerResolver, and that constructors exist for specifying different locations for these files. I hope you find this information useful.

或许这个已经在新版本里面已经fixed了,我已经下了最新的版本,还没有来得及测试。

如果你也遇到这个问题,首先恭喜你。

其次,你可以按照以上的方式做一个 “your own "custom" version of these three files”,使用

  1. //IOUtils and FileUtils come from Apache Commons IOfor(String s : new String[] {"spring.schemas", "spring.handlers", "spring.tooling"}) {
  2. Enumeration<?> e = Test.class.getClassLoader().getResources("META-INF/"+s);
  3. StringBuilder out = new StringBuilder();while(e.hasMoreElements()) { URL u = (URL) e.nextElement(); out.append(IOUtils.toString(u.openStream())).append("\n"); }
  4. File outf = new File(s);
  5. FileUtils.writeStringToFile(outf, out.toString(), "UTF-8");
  6. }

合并文件以后,来代替jar包中\META-INF\spring.schemas,\META-INF\spring.handlers,

\META-INF\spring.tooling,就可以了.

最好的办法是通过maven去打包在POM.xml中增加

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-shade-plugin</artifactId>
  4. <version>1.6</version>
  5. <configuration>
  6. <!-- put your configurations here -->
  7. </configuration>
  8. <executions>
  9. <execution>
  10. <phase>package</phase>
  11. <goals>
  12. <goal>shade</goal>
  13. </goals>
  14. <configuration>
  15. <transformers>
  16. <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  17. <manifestEntries>
  18. <Main-Class>util.Process</Main-Class>
  19. </manifestEntries>
  20. </transformer>
  21. <transformer
  22. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  23. <resource>META-INF/cxf/bus-extensions.txt</resource>
  24. </transformer>
  25. <transformer
  26. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  27. <resource>META-INF/spring.handlers</resource>
  28. </transformer>
  29. <transformer
  30. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  31. <resource>META-INF/spring.tooling</resource>
  32. </transformer>
  33. <transformer
  34. implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  35. <resource>META-INF/spring.schemas</resource>
  36. </transformer>
  37. </transformers>
  38. </configuration>
  39. </execution>
  40. </executions>
  41. </plugin>

来合并这些文件,来保证在打包时这些文件不会互相覆盖。

Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace的更多相关文章

  1. spring 与 CXF 整合 webservice 出现error “Unable to locate Spring NamespaceHandler for XML schema namespace” 总结

    我试了多个版本的spring 发现 出现error : Unable to locate Spring NamespaceHandler for XML schema namespace 并非都是sp ...

  2. Unable to locate Spring NamespaceHandler for XML schema namespace

    1. 问题 本文将讨论Spring中最常见的配置问题 —— Spring的一个命名空间的名称空间处理程序没有找到. 大多数情况下,是由于一个特定的Spring的jar没有配置在classpath下,让 ...

  3. 运行maven打出来的jar包报错:Unable to locate Spring NamespaceHandler for XML schema namespace

    问题背景:新建了一个maven项目,打了一个可运行jar包,依赖了spring几个jar包,一跑就报错了 E:\workspace\point-circle\target>java -jar p ...

  4. [java] bug经验 Unable to locate Spring NamespaceHandler for XML schema namespace解决办法

    报错关键字: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration probl ...

  5. jar项目 BeanDefinitionParsingException: Configuration problem:Unable to locate Spring NamespaceHandler for XML schema namespace

    最近由于项目需要,需要jar项目来处理. 我在项目中整合了Spring,在编辑器中启动没有问题,但是使用ant打包为一个完整jar文件,部署后启动报错如下 org.springframework.be ...

  6. onfiguration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...

  7. 打成Jar包后运行报错 Unable to locate Spring NamespaceHandler for XML schema namespace

    MAVEN项目,在IDEA中运行正常,但是把它打成jar包后再运行就会出现异常:   Exception in thread "main" org.springframework. ...

  8. Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]

    ERROR - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsin ...

  9. mvn打包spring工程成jar时报Unable to locate Spring NamespaceHandler for XML schema namespace错误解决办法

    有一个小工程,使用了spring,在使用maven的assembly打包成独立可执行的jar包后,在执行时报如下错误:Configuration problem: Unable to locate S ...

随机推荐

  1. Bootstrap Paginator 分页 demo.

    效果如下: 需要的引用以下内容 bootstrap2 http://cnbootstrap.com/ bootstrap-paginator v0.5 主页 http://bootstrappagin ...

  2. [DevExpress]ChartControl之时间轴示例

    关键代码: using System; using System.Data; using System.Windows.Forms; using DevExpress.XtraCharts; name ...

  3. 简单方便的在线客服展示插件 jQuery.onServ

    onServ jQuery.onServ 是一款简单方便的在线客服jQuery 插件,可以使任意html实现弹出展示在线客服效果, 可以自定义内容,简单配置出多个弹出动作特效,设置位置和样式. git ...

  4. 演出排期JavaScript

    <script language="JavaScript" type="text/javascript"> var diarydays=" ...

  5. EventHandler委托的使用

    今天复习了一下事件和委托,本来看事件来着,看到EventHandler,写了一个小例子,想贴在这里解释一下.为了弄清楚EventHandler, 还是回归到最基本的委托,曾经在园子里看到一位前辈用深入 ...

  6. ros-Qt代码环境的搭建

    1 建立package catkin_create_pkg beginner_tutorials roscpp 2 导入Qt Qt中打开整个工作空间的src/CMakeLists.txt 在倒数第二行 ...

  7. Python脚本控制的WebDriver 常用操作 <十九> 获取测试对象的状态

    下面将使用webdriver来模拟测试中观察测试对象的状态的操作 测试用例场景 在web自动化测试中,我们需要获取测试对象的四种状态 是否显示.使用element.is_displayed()方法: ...

  8. CentOS 6.4 安装搭建 Scrapy 0.22 环境

    一.安装Python2.7.6 更新CentOS lib库文件 yum -y update 安装开发工具包 yum groupinstall -y development 安装扩展包 yum inst ...

  9. SQLserver利用系统时间生成“2015-11-30 00:00:00.000”类型的时间

    select getdate() ---当前时间:2015-12-18 10:20:24.097 -------------------建立测试表 Create Table #Test ( ID IN ...

  10. java 产生随机数的方法

    有三种方法: Math.random():这个方法返回一个[0.0, 1.0)的一个随机double型数.它实际是调用Random类的nextDouble()方法.只不过Math类使用的是一个静态随机 ...