Key Words
Spring 3.0
Apache CXF 2.X.X
昨日,在原本应用中添加了关于webService的调用,使用了Apache CXF 框架,并将其集成到了Spring中。
当时集成时,使用了如下的jar包(Spring2.5.5.JPG)
加入CXF的相关jar包
然后将WebService客户端集成到Spring中,代码类似于:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="helloClient"
serviceClass="demo.spring.HelloWorld"
address="http://localhost:9002/HelloWorld" />
</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”,使用
//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");
}
合并文件以后,来代替jar包中\META-INF\spring.schemas,\META-INF\spring.handlers,
\META-INF\spring.tooling,就可以了.
最好的办法是通过maven去打包在POM.xml中增加
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>util.Process</Main-Class>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/cxf/bus-extensions.txt</resource>
</transformer>
<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.tooling</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
来合并这些文件,来保证在打包时这些文件不会互相覆盖。
- 大小: 49.4 KB
- 大小: 22.8 KB
- 大小: 26.7 KB
- 大小: 6.9 KB
分享到:
相关推荐
使用assembly插件打包jar后启动时,总是出现Unable to locate Spring NamespaceHandler for XML schema....错误,网上找了各种方法都没有用,在尝试了100+失败后,解决了这个问题,在打包的jar中,META-INF目录下,...
selenium+firefox在定位时遇到selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: 由于是js加载页面,想确认是否是js的原因,随后进行多次调试时发现“//div”竟然也出现了...
Mingw32(Minimalist GNU for Windows 32-bit)是一种流行的交叉编译工具链,它可以用来在非 Windows 平台(如 Linux 或 Unix)上编译出可以在 Windows 上运行的程序。本文将详细介绍如何在 Ubuntu 系统中搭建一个...
在搭建spring项目时通常需要这些jar包 ...org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace ...
在Linux系统中,GCC(GNU Compiler Collection)是一个关键的开源工具链,用于编译C、C++、Fortran、Objective-C等编程语言的源代码。它不仅包括了编译器,还包括预处理器、链接器和其他相关工具。...
1、Unable to locate provider for protocol: smtp –>缺少依赖造成的 <groupId>javax.mail <artifactId>mail <version>1.4 <groupId>javax.activation <artifactId>activation</artifactId>
在使用Qt进行串行通信开发时,可能会遇到一个与Qt Serialbus模块相关的错误,提示“dropping older ADU fragments due to larger than 3.5 char”。这个错误通常出现在处理CAN(Controller Area Network)协议的数据...
软件介绍: 如果你的系统因各种原因出现开机不能引导,引导文件损坏不能进系统,不需要重新系统,先使用本工具进行修复,将系统引导修复工具BootRepair放到带有PE启动的U盘中,使用U盘来引导系统,运行Boot...
在文档中提到的“Linux System Administration 1 Study Guide for Labwork for LPI 101”是一个针对Linux专业人士认证(Linux Professional Institute Certification)第一级别(LPI 101)的学习指南。LPI是一个全球...
5. **MySQL客户端**:`Navicat for MySQL`是常见的数据库管理工具,它提供了一个图形化的界面,使得用户可以更轻松地连接到MySQL服务器,执行SQL查询、管理数据库对象(如表、视图、存储过程)以及进行数据导入导出...
在“spring-batch-example”这个压缩包中,我们很可能会找到一些示例代码或配置文件,展示如何在实际项目中利用Spring Batch的临时存储特性。这些示例可能包含如何设置JobRepository,如何定义分片策略,以及如何...
下载opencv.zip 要提前安装依赖项。 先更新一下下载源。...errorE: unable to locate libjasper-dev 解决方法 sudo add-apt-repository “deb http://security.ubuntu.com/ubuntu xenial-security main” sudo a
Jetson系列是由NVIDIA推出的专为边缘计算和人工智能应用设计的一系列嵌入式计算平台。这些设备,如TX2、NX和AGX,拥有强大的CPU和GPU能力,为物联网(IoT)、自动驾驶、机器人和其他低功耗高性能计算场景提供了理想的...
**glib2-devel** 是一个开发包,主要针对软件开发者,特别是那些在Linux或类Unix系统上使用GLib库进行程序开发的人。GLib是GObject基础库的一部分,提供了核心数据类型、内存管理、线程支持、日志系统以及各种实用...
lingo0.9破解版
报错:java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.-附件资源
该文件能够解决bug:Could not locate zlibwapi.dll. Please make sure it is in your library path!遇到这个bug可以通过下载该文件解决,具体教程见博主的博客。相信很多深度学习小白都遇到了这个bug,快来下载解决...
copy-webpack-plugin-demo.rar 拷贝文件demo, 现成案例,可以参考使用 免积分下载地址 https://download.lllomh.com/cliect/#/product/JB23148366892270
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace ...