打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Unable to locate Spring NamespaceHandler for XML schema namespace 问题的解决

被这个问题折磨着很久:参考: 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)

 

 


 

这就是导致出现

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>  

 

 

 

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

I'm falling off the sky all alone.The courage inside is gonna break the fall. Nothing can dim my light within. I am That I am 程序 = 数据结构 + 算法
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用maven插件对java工程进行打包
Java系列---Maven插件(与maven的生命周期相关)
这样优化Spring Boot,启动速度快到飞起!
CXF JMS Transport
记一次问题排查发现的spring-ldap的bug
如何查看现有项目的struts和hibernate和spring版本
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服