被这个问题折磨着很久:参考: 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中,代码类似于:

Xml代码  收藏代码
  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”,使用

Java代码  收藏代码
  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中增加

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>

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

转载于:https://www.cnblogs.com/IamThat/p/4603800.html

Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace相关推荐

  1. Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]

    利用cxf调试webservice接口的时候出现下面的错误 error:Unable to locate Spring NamespaceHandler for XML schema namespac ...

  2. 前沿资讯|Spring Native 0.11.2、Spring Authorization Server 0.2.2 发布

    近日,Spring官方又更新了两个前沿内容,分别是Spring Native 0.11.2 和Spring Authorization Server 0.2.2 .下面一起来看看分别都更新了些什么. ...

  3. java基础巩固-宇宙第一AiYWM:为了维持生计,Spring全家桶_Part1-3(学学Spring源码呗:默认的标签和自定义标签是咋解析的)~整起

    Part3:上一次说到了Spring的DefaultBeanDefinitionDocumentReader类中的parseBeanDefinitions(Element root, BeanDefi ...

  4. Spring 2.0.1 与 BEA WebLogic Server 9.2 的集成

    http://www.oracle.com/technetwork/cn/topics/entarch/spring-2-weblogic-server-9-integrat-091510-zhs.h ...

  5. JAVA SSH框架的配置(myeclipse(9)+tomcat(6.0.35)+struts(2.2.3)+Spring(3.0)+Hibernate(3.0))

    http://www.cnblogs.com/piahb605/archive/2011/12/25/2301091.html 1.安装java环境,jdk1.7.0_01,配置环境变量及JAVA_H ...

  6. 告诉老默我想学Spring Cloud了(新手篇):从0到1搭建Spring Cloud项目(实际项目开发的浓缩精华版)

    告诉老默我想学Spring Cloud了(新手篇):从0到1搭建Spring Cloud项目 一.前言 二.如何选择版本 2.1 SpringCloud 和 Spring Boot 版本选型 2.1. ...

  7. 有关Spring 3.0的发布

    今天SpringSource大张旗鼓的宣布Spring 3.0的降临,一时间占据了各大外媒的醒目位置(不过说实话,时机还是不太好,和Visual Studio 2010 Beta 2撞一天了,在头条位 ...

  8. 【转载】详解 Spring 3.0 基于 Annotation 的依赖注入实现

    转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-iocannt/ Spring 的依赖配置方式与 Spring 框架的 ...

  9. Diagram of Spring 3.0 module dependencies--转载

    原文地址:http://www.ogrigas.eu/spring/2009/12/diagram-of-spring-3-0-module-dependencies As Spring 3.0.0. ...

  10. 详解 Spring 3.0 基于 Annotation 的依赖注入实现--转载

    使用 @Repository.@Service.@Controller 和 @Component 将类标识为 Bean Spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的 ...

最新文章

  1. 编码区和非编码区的关系
  2. 一个封装的使用Apache HttpClient进行Http请求(GET、POST、PUT等)的类。
  3. Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Find/undo事件)
  4. 【初码干货】关于.NET玩爬虫这些事
  5. hdu 4585 Shaolin set
  6. jvm高并发_JVM上的高并发HTTP客户端
  7. vue 2个方法先后执行_有效快速制作工资条的2个方法
  8. 从零基础到精通的前端学习路线
  9. .NetCore上传多文件的几种示例
  10. C++ 类的静态成员变量为什么一定要初始化
  11. 如何找到外文文献对应的中文文献?
  12. 2017年11月19日实验感想
  13. 未名湖边的桃花儿开了,就在前几天。
  14. App项目开发流程图解
  15. (HDU-1564)Play a game(博弈论)
  16. 盛水容器问题php代码,盛水容器的形状如图2-13所示,已知各水面高程为▽1=1.15m,▽2=0.68m,▽3=0.44m...
  17. cheat sheet 打包打印版大全python R machine learning
  18. PS10修复工具组(人物祛斑),PS12强大的画笔工具(手绘),PS13铅笔工具(颜色替换)
  19. JavaWeb技术内幕八:JVM内存管理
  20. 计算机课 - 计算机科学导论

热门文章

  1. 【js高三】---js模块模式
  2. Redis-数据结构与对象
  3. 如何做好一个流量站?
  4. android CheckBox的运用
  5. uva 1045(二分图最大权匹配)
  6. brew 安装软件能指定文件夹吗_Mac安装homebrew安装到指定目录
  7. python遍历字典修改值_Python中遍历字典过程中更改元素导致异常的解决方法
  8. linspace函数matlab_MATLAB用不同颜色绘制多条曲线
  9. java jpa自身关联_java-如何通过JPA / Hibernate加入获取两个关联
  10. apt-get update出现NO_PUBKEY问题解决