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

最新文章

  1. 网易云信,发送验证码短信C#版代码
  2. OpenCascade Primitives BRep - Box
  3. Select-or-Die:灵活的 jQuery 下拉列表插件
  4. git 使用笔记(一)
  5. Linux内核:关于中断你须要知道的
  6. cocoa pods出现的错误
  7. [原]iOS中 Web 页面与 Native Code 的一种通信方式
  8. c语言-error C2440: “static_cast”: 无法从“UINT (__thiscall CHyperLink::* )(CPoint)”转换为“LRESULT (__thiscall CWnd::* )(CPoint)”
  9. java面向对象浅析
  10. 跟着小菜学习RabbitMQ启动和基础(系列一)
  11. SQL Server使用sp_rename重命名约束注意事项
  12. Oracle 中sql文件的导入导出
  13. Linux零基础入门第五课
  14. C语言调用Python 混合编程
  15. (C/C++学习笔记) 六. 表达式
  16. xlwt使用
  17. 使用gearman进行异步的邮件或短信发送
  18. Ubuntu菜鸟入门(十四)—— 设置root密码
  19. mha切换脚本可用的
  20. 【GIS】WGS84与Web墨卡托理解(转)

热门文章

  1. 10.17小作业 基于TCP开发一款远程CMD程序
  2. 自定义 Swiper 的pageControl
  3. maven项目创建3 (依赖版本冲突)
  4. Flash大文件断点续传功能
  5. 网页“console”输出图文信息
  6. 在网页中嵌套网页的方法(frame)
  7. 浏览器使用小tip
  8. Spring配置文件beans标签报错问题解决
  9. war包部署到tomcat
  10. Java并发编程的艺术笔记(四)——ThreadLocal的使用