Unable to locate Spring NamespaceHandler for XML schema namespace

来源:互联网 发布:淘宝拿货网 编辑:程序博客网 时间:2024/05/17 20:27

今天在测试NetBeans打包的jar包程序的时候发现一个诡异的spring异常,此异常在IDE调试中不存在,但在测试环境中打包后即出现,错误日志如下

Exception in thread "AWT-EventQueue-0" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: file [D:\work\ccsweb\test\exe\applicationContext.xml]


异常出现的原因是

如果工程中依赖了Spring的多个依赖,在打包时后面的会把前面的覆盖,使得这两个文件中永远只保存最后一个spring依赖的schema和handler

解决方法

我使用netbeans自带的build.xml编译的,所以不知道怎么修改配置文件。自己测试了一个简洁的方法,就是根据提示少的那行内容,在打好Jar底下的

META-INF文件夹中找到spring.handler如下图

原来spring.handlers的内容是如下:

http\://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler

手动添加上一行

http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler

问题解决

0 0
原创粉丝点击