原文地址:
http://www.baeldung.com/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace
1. The Problem
This article will discuss one of the most common configuration problems in Spring – a namespace handler for one of the Spring namespaces is not found. Most of the time, this means one particular Spring jar is missing from the classpath – so let’s go over what these missing schemas might be, and what the missing dependency is for each one.
2. http://www.springframework.org/schema/security
The security namespace not being available is by far the most widely encountered problem in practice:
?
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
</beans:beans>
Which leads to the following exception:
?
1
2
3
4
5
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem:
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/security]
Offending resource: class path resource [securityConfig.xml]
The solution is straightforward – the spring-security-config dependency is missing from the classpath of the project:
?
1
2
3
4
5
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
This will put the correct namespace handler – in this case SecurityNamespaceHandler – on the classpath and ready to parse the elements in the security namespace.
The complete Maven configuration for a full Spring Security setup can be found in my previous Maven tutorial.
3. http://www.springframework.org/schema/aop
The same problem occurs when using the aop namespace without having the necessary aop spring library on the classpath:
?
1
2
3
4
5
6
7
8
9
10
11
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
</beans>
The exact exception:
?
1
2
3
4
5
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem:
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/aop]
Offending resource: ServletContext resource [/WEB-INF/webConfig.xml]
The solution is similar – the spring-aop jar needs to be added to the classpath of the project:
?
1
2
3
4
5
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
In this case, the AopNamespaceHandler will be present on the classpath after adding the new dependency.
4. http://www.springframework.org/schema/tx
Using the transaction namespace – a small but very useful namespace for the configuration of the transactional semantics:
?
1
2
3
4
5
6
7
8
9
10
11
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
</beans>
will also result in an exception if the right jar is not on the classpath:
?
1
2
3
4
5
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem:
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/tx]
Offending resource: class path resource [daoConfig.xml]
The missing dependency here is spring-tx:
?
1
2
3
4
5
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
Now, the right NamspaceHandler – namely TxNamespaceHandler – will be present on the classpath allowing the declarative transaction management with both XML and annotations.
5. http://www.springframework.org/schema/mvc
Moving forward to the mvc namespace:
?
1
2
3
4
5
6
7
8
9
10
11
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
</beans>
The missing dependency will lead to the following exception:
?
1
2
3
4
5
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem:
Unable to locate Spring NamespaceHandler for XML schema namespace
[http://www.springframework.org/schema/mvc]
Offending resource: class path resource [webConfig.xml]
In this case, the missing dependency is spring-mvc:
?
1
2
3
4
5
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
Adding this to the pom.xml will add the MvcNamespaceHandler to the classpath – allowing the project to configure MVC semantics using the namespace.
6. Conclusion
Finally, if you’re using Eclipse to manage the web server and deploy – make sure that the Deployment Assembly section of the project is correctly configured – namely that the Maven dependencies actually are included on the classpath at deployment time.
This tutorial discussed the usual suspects for the “Unable to locate Spring NamespaceHandler for XML schema namespace” problem and provided solutions for each occurrence.
分享到:
相关推荐
使用assembly插件打包jar后启动时,总是出现Unable to locate Spring NamespaceHandler for XML schema....错误,网上找了各种方法都没有用,在尝试了100+失败后,解决了这个问题,在打包的jar中,META-INF目录下,...
在搭建spring项目时通常需要这些jar包 ...org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace ...
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,如何定义分片策略,以及如何...
selenium+firefox在定位时遇到selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: 由于是js加载页面,想确认是否是js的原因,随后进行多次调试时发现“//div”竟然也出现了...
在Linux系统中,GCC(GNU Compiler Collection)是一个关键的开源工具链,用于编译C、C++、Fortran、Objective-C等编程语言的源代码。它不仅包括了编译器,还包括预处理器、链接器和其他相关工具。...
lingo0.9破解版
1、Unable to locate provider for protocol: smtp –>缺少依赖造成的 <groupId>javax.mail <artifactId>mail <version>1.4 <groupId>javax.activation <artifactId>activation</artifactId>
copy-webpack-plugin-demo.rar 拷贝文件demo, 现成案例,可以参考使用 免积分下载地址 https://download.lllomh.com/cliect/#/product/JB23148366892270
Mingw32(Minimalist GNU for Windows 32-bit)是一种流行的交叉编译工具链,它可以用来在非 Windows 平台(如 Linux 或 Unix)上编译出可以在 Windows 上运行的程序。本文将详细介绍如何在 Ubuntu 系统中搭建一个...
Unable to locate decompressor to decompress video stream 此时即可利用此软件进行转换,转为'Cinepak'压缩格式的avi视频…… 转化完成后,利用aviinfo即可看到转化后avi视频的压缩格式…… 然后就可以...
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 System Administration 1 Study Guide for Labwork for LPI 101”是一个针对Linux专业人士认证(Linux Professional Institute Certification)第一级别(LPI 101)的学习指南。LPI是一个全球...
软件介绍: 如果你的系统因各种原因出现开机不能引导,引导文件损坏不能进系统,不需要重新系统,先使用本工具进行修复,将系统引导修复工具BootRepair放到带有PE启动的U盘中,使用U盘来引导系统,运行Boot...
主要介绍了Python3 venv搭建轻量级虚拟环境的步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
BCGControlBarPro.v12.00完整源代码(含资源汉化帮助文件和VS2008中文向导)第三部分 使用方法: ... ...2、双击导入注册表C:\Program Files\BCGSoft\BCGControlBarPro\bcgcontrolbarpro.12.00.reg;...
在Linux系统中,`lib64stdc++6_6.2.0-5ubuntu12_i386.tar.gz`是一个重要的库文件,用于支持C++编程语言的运行环境。这个压缩包包含了`libstdc++.so.6.0.22`,这是一个动态链接库,是GNU C++标准库的组成部分,对于...
在使用Qt进行串行通信开发时,可能会遇到一个与Qt Serialbus模块相关的错误,提示“dropping older ADU fragments due to larger than 3.5 char”。这个错误通常出现在处理CAN(Controller Area Network)协议的数据...