Unable to locate Spring NamespaceHandler for XML schema namespace
1. 问题
本文将讨论Spring中最常见的配置问题 —— Spring的一个命名空间的名称空间处理程序没有找到。 大多数情况下,是由于一个特定的Spring的jar没有配置在classpath下,让我们列出多数可能出现的缺失配置以及导致的异常。
2. http://www.springframework.org/schema/security
安全名称空间可能是迄今为止在实践中遇到的最广泛的问题:

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

导致以下异常:
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]
解决方法很简单 —— 把spring-security-config的jar配置在classpath中(如:maven的pom.xml):
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
配置正确的名称空间处理程序 —— 在这种情况下classpath下的SecurityNamespaceHandler会解析安全名称空间中的元素。
3. http://www.springframework.org/schema/aop
发生在使用aop名称空间时,没有将相应的spring的jar配置在classpath下:

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

导致以下异常:
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]
解决方法与问题2类似,只需将spring-aop的jar配置calsspath下:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
4. http://www.springframework.org/schema/tx
使用事务名称空间 —— 一个小但非常有用的名称空间配置:

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

导致以下异常:
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]
解决方法,将事务的jar配置到classpath下:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
5. http://www.springframework.org/schema/mvc
下面是spring的mvc名称空间

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

导致以下异常:
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]
遇到这种异常,是因为没有将spring的mvc的jar配置在classpath中:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
6.结论
最后,如果你是使用Eclipse来管理web服务器和部署,确保部署的组装部分项目是配置正确的 —— 即Maven的依赖,实际上是在部署时包含在类classpath中。
Unable to locate Spring NamespaceHandler for XML schema namespace的更多相关文章
- onfiguration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Una ...
- spring 与 CXF 整合 webservice 出现error “Unable to locate Spring NamespaceHandler for XML schema namespace” 总结
我试了多个版本的spring 发现 出现error : Unable to locate Spring NamespaceHandler for XML schema namespace 并非都是sp ...
- Spring 3.0: Unable to locate Spring NamespaceHandler for XML schema namespace
被这个问题折磨着很久:参考: http://have23.iteye.com/blog/1340777 (cfx 与 spring 整合的时候出现的问题: org.springframework.be ...
- 打成Jar包后运行报错 Unable to locate Spring NamespaceHandler for XML schema namespace
MAVEN项目,在IDEA中运行正常,但是把它打成jar包后再运行就会出现异常: Exception in thread "main" org.springframework. ...
- Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
ERROR - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsin ...
- mvn打包spring工程成jar时报Unable to locate Spring NamespaceHandler for XML schema namespace错误解决办法
有一个小工程,使用了spring,在使用maven的assembly打包成独立可执行的jar包后,在执行时报如下错误:Configuration problem: Unable to locate S ...
- 运行maven打出来的jar包报错:Unable to locate Spring NamespaceHandler for XML schema namespace
问题背景:新建了一个maven项目,打了一个可运行jar包,依赖了spring几个jar包,一跑就报错了 E:\workspace\point-circle\target>java -jar p ...
- [java] bug经验 Unable to locate Spring NamespaceHandler for XML schema namespace解决办法
报错关键字: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration probl ...
- jar项目 BeanDefinitionParsingException: Configuration problem:Unable to locate Spring NamespaceHandler for XML schema namespace
最近由于项目需要,需要jar项目来处理. 我在项目中整合了Spring,在编辑器中启动没有问题,但是使用ant打包为一个完整jar文件,部署后启动报错如下 org.springframework.be ...
随机推荐
- ip route 命令详解
linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...
- 牛客网剑指Offer——正则表达式匹配
1. 题目描述 请实现一个函数用来匹配包括'.'和'*'的正则表达式.模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次). 在本题中,匹配是指字符串的所有字符匹配整 ...
- 网络基础和python(二)
一,五层协议 应用层 端口 传输层 tcp\udp 网络层 ipv4\6 数据链路层 ethernet 物理层 mac 二:什么是变量? 变量:核心在于变和量儿字,变->变 ...
- Linux性能及调优指南1.2之Linux内存架构
本文为IBM RedBook的Linux Performanceand Tuning Guidelines的1.2节的翻译原文地址:http://www.redbooks.ibm.com/redpap ...
- Solr进阶之Solr综合文本相似度的多因素权重排序实现
现在有个需求是这样子的:需要计算搜索词的权重设置其为总排序权重的0.6,其他因素的权重为0.4其他因素中还有详细的划分.这里我们用Solr如何来实现?众所周知solr默认的排序方式为按照文本相似度来进 ...
- solr7.4 tomcat环境下搭建(windows)
-版本solr-7.4.0 -环境 Windows jdk1.8 -启动方式:部署在apache-tomcat-8.5.28,以下简称Tomcat 1. 将solr-7.4.0\server\sol ...
- sql server 给表加说明,给列/字段加说明
--sql server给表加说明: --banner EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Banner ...
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
在Mysql集群中创建用户时.出现如下错误! mysql> create user 'testuse'@'localhost' identified by '111111'; ERROR 129 ...
- ASP.NET 实现重启系统或关机
在C#程序中实现电脑的关机.重启,两种方法可以实现: 方法1:启动Shell进程,调用外部命令shutdown.exe来实现. 首先导入命名空间using System.Diagnostics;然后, ...
- js调用打印机打印
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...