`
chenzhou123520
  • 浏览: 4263160 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Unable to locate Spring NamespaceHandler for XML schema namespace

阅读更多

java服务中整合了spring,在Eclipse里本地启动时没问题,但是部署到局域网linux服务器上时解析spring applicationContext.xml报错,具体报错信息如下:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]

 

关于这个问题,纠结了我大半天时间,网上的资料也是众说纷纭,有的说是spring版本不统一、有些说是缺少对应的spring依赖的。不过这些原因都被我逐一排除了。

 

功夫不负有心人,在仔细地对比和排查原因之后,发现了问题的所在,在我的jar包下的META-INF目录下,有两个跟spring相关的文件:spring.handlers、spring.schemas,打开这两个文件一看,里面都只包含了spring-tx的配置

spring.handlers:

http\://www.springframework.org/schema/tx=org.springframework.transaction.config.TxNamespaceHandler

spring.schemas:

http\://www.springframework.org/schema/tx/spring-tx-2.0.xsd=org/springframework/transaction/config/spring-tx-2.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-2.5.xsd=org/springframework/transaction/config/spring-tx-2.5.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.0.xsd=org/springframework/transaction/config/spring-tx-3.0.xsd
http\://www.springframework.org/schema/tx/spring-tx-3.1.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd
http\://www.springframework.org/schema/tx/spring-tx.xsd=org/springframework/transaction/config/spring-tx-3.1.xsd

里面并没有spring-context的schema和handler配置,所以会报错。

 

那么问题的根源是什么呢,在stackoverflow上找到了答案:http://stackoverflow.com/questions/1937767/spring-3-0-unable-to-locate-spring-namespacehandler-for-xml-schema-namespace

 

因为我使用了maven-shade-plugin这个maven打包插件,主要原因是插件配置不当导致,我原来的配置如下:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-shade-plugin</artifactId>
	<version> 1.7.1</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>shade</goal>
			</goals>
			<configuration>
				<transformers>
					<transformer
						implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
						<mainClass>com.chenzhou.test.Main</mainClass>
					</transformer>
				</transformers>
			</configuration>
		</execution>
	</executions>
</plugin>

由于没有配置META-INF/spring.handlers和META-INF/spring.schemas所以如果工程中依赖了Spring的多个依赖,在打包时后面的会把前面的覆盖,使得这两个文件中永远只保存最后一个spring依赖的schema和handler。

解决方法就是在里面加上META-INF/spring.handlers和META-INF/spring.schemas的配置:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-shade-plugin</artifactId>
	<version> 1.7.1</version>
	<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>
					<transformer
						implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
						<mainClass>com.chenzhou.test.Main</mainClass>
					</transformer>
				</transformers>
			</configuration>
		</execution>
	</executions>
</plugin>

和第一段配置对比,主要增加了:

<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>

这段配置意思是把spring.handlers和spring.schemas文件以append方式加入到构建的jar包中。

 

修改完后,再次打包,此时就会把工程依赖的所有的spring依赖的schema和handler都加载到spring.handlers和spring.schemas里面。加载applicationContext.xml时就不会报错了。

 

关于maven-shade-plugin的使用,可以参考我另外一篇博文:使用maven插件对java工程进行打包

分享到:
评论
8 楼 promisepk 2017-06-28  
虽然已经找到 原因了,但是楼主写的还是很清楚 的
7 楼 南蚁北漂 2016-07-02  
不错,学习了!http://cobaya.cn/
6 楼 羽风之扬 2016-05-31  
你好,我有个问题向你请教下,发你邮箱了,麻烦看下,谢谢!
5 楼 Atk 2014-11-17  
非常感谢,我也是这个问题,解决了。
4 楼 t2xingzhe 2014-06-09  
这个一定要感谢下,帮我大忙了
3 楼 chenzhou123520 2014-04-02  
eddie_520 写道
没好使啊,还是那个错误!

我现在自己和公司都是用的这种方式打包的,是没问题的啊,不知道是不是你没配置好还是什么原因,如果不涉及到机密的话可以把工程发给我我给你测试一下: chenzhou1025@126.com
2 楼 eddie_520 2014-03-21  
我记得我给你留言了?删了?
1 楼 eddie_520 2014-03-21  
没好使啊,还是那个错误!

相关推荐

    maven项目使用assembly打包jar时处理Unable to locate Spring NamespaceHandler问题

    使用assembly插件打包jar后启动时,总是出现Unable to locate Spring NamespaceHandler for XML schema....错误,网上找了各种方法都没有用,在尝试了100+失败后,解决了这个问题,在打包的jar中,META-INF目录下,...

    springAOP demo 带错误解决文档

    在搭建spring项目时通常需要这些jar包 ...org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace ...

    Maven打包指南

    Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace ...

    临时存储

    在“spring-batch-example”这个压缩包中,我们很可能会找到一些示例代码或配置文件,展示如何在实际项目中利用Spring Batch的临时存储特性。这些示例可能包含如何设置JobRepository,如何定义分片策略,以及如何...

    《python3网络爬虫开发实战》学习笔记::selenium——xpath:Unable to locate element

    selenium+firefox在定位时遇到selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: 由于是js加载页面,想确认是否是js的原因,随后进行多次调试时发现“//div”竟然也出现了...

    linux gcc install

    在Linux系统中,GCC(GNU Compiler Collection)是一个关键的开源工具链,用于编译C、C++、Fortran、Objective-C等编程语言的源代码。它不仅包括了编译器,还包括预处理器、链接器和其他相关工具。...

    lingo0.9破解版

    lingo0.9破解版

    Ubuntu 12.04(64bit) server 安装 Oracle 11G(最新问题解决)

    在本文中,我们将深入探讨如何在Ubuntu 12.04(64位)服务器上安装Oracle 11G数据库,以及解决可能遇到的最新问题。在开始之前,请确保你的系统是最新版本,通过运行以下命令进行更新和升级: ...

    SpringMail使用过程中的报错解决办法

    1、Unable to locate provider for protocol: smtp –&gt;缺少依赖造成的 &lt;groupId&gt;javax.mail &lt;artifactId&gt;mail &lt;version&gt;1.4 &lt;groupId&gt;javax.activation &lt;artifactId&gt;activation&lt;/artifactId&gt;

    关于Matlab处理avi视频视频转换软件-XviD-1.2.2-07062009.rar

    Unable to locate decompressor to decompress video stream 此时即可利用此软件进行转换,转为'Cinepak'压缩格式的avi视频…… 转化完成后,利用aviinfo即可看到转化后avi视频的压缩格式…… 然后就可以...

    ubuntu下mingw32交叉编译环境搭建

    Mingw32(Minimalist GNU for Windows 32-bit)是一种流行的交叉编译工具链,它可以用来在非 Windows 平台(如 Linux 或 Unix)上编译出可以在 Windows 上运行的程序。本文将详细介绍如何在 Ubuntu 系统中搭建一个...

    BCGControlBarPro.v12.00

    Implemented ability to add Ribbon Galleries to the dialogs (see screenshot). The new class CBCGPRibbonGalleryCtrl may be used for this purpose. Please take a look at BCGPMSOffice2007Demo example ...

    linux esential

    在文档中提到的“Linux System Administration 1 Study Guide for Labwork for LPI 101”是一个针对Linux专业人士认证(Linux Professional Institute Certification)第一级别(LPI 101)的学习指南。LPI是一个全球...

    玩酷之家系统引导修复工具BootRepair.rar

    软件介绍:  如果你的系统因各种原因出现开机不能引导,引导文件损坏不能进系统,不需要重新系统,先使用本工具进行修复,将系统引导修复工具BootRepair放到带有PE启动的U盘中,使用U盘来引导系统,运行Boot...

    Python3 venv搭建轻量级虚拟环境的步骤(图文)

    主要介绍了Python3 venv搭建轻量级虚拟环境的步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

    VC 作界面库 美化 设计开发必备库BCGControlBarPro.v12.00完整源代码(破解版)

    BCGControlBarPro.v12.00完整源代码(含资源汉化帮助文件和VS2008中文向导)第三部分 使用方法: ... ...2、双击导入注册表C:\Program Files\BCGSoft\BCGControlBarPro\bcgcontrolbarpro.12.00.reg;...

    lib64stdc++6_6.2.0-5ubuntu12_i386.tar.gz

    在Linux系统中,`lib64stdc++6_6.2.0-5ubuntu12_i386.tar.gz`是一个重要的库文件,用于支持C++编程语言的运行环境。这个压缩包包含了`libstdc++.so.6.0.22`,这是一个动态链接库,是GNU C++标准库的组成部分,对于...

    解决Qt Serialbus 报错3.5char问题源码

    在使用Qt进行串行通信开发时,可能会遇到一个与Qt Serialbus模块相关的错误,提示“dropping older ADU fragments due to larger than 3.5 char”。这个错误通常出现在处理CAN(Controller Area Network)协议的数据...

    docker容器调用yum报错的解决办法

    在本篇文章里小编给大家分享的是关于docker容器调用yum报错的解决办法,有兴趣的朋友们可以参考下。

Global site tag (gtag.js) - Google Analytics