博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring的一个命名空间的名称空间处理程序没有找到
阅读量:4188 次
发布时间:2019-05-26

本文共 4190 字,大约阅读时间需要 13 分钟。

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

转载地址:http://odnoi.baihongyu.com/

你可能感兴趣的文章
Visual Studio 2008 VPC Beta 2 版本 將於今日過期.
查看>>
ASP.NET AJAX 新書完稿.
查看>>
Silverlight 完全中文解決方案
查看>>
精彩的瀏覽器戰爭的序幕已拉開
查看>>
Silverlight 與 ASP.NET 的完美結合法 - 控件篇
查看>>
Silverlight DataBindings for 1.1 (Managed code)
查看>>
另類的Silverlight中文解法
查看>>
我的年度計劃-流產表...........
查看>>
Vista 與輸入法程式介面
查看>>
複合式 LINQ.
查看>>
瀏覽器平台上的戰爭,Silverlight,Flash,Flex,JavaFX
查看>>
WPF UI介面的革新
查看>>
3月14日相约CSDN聊天室: ASP.NET 想说爱你并不件容易的事?
查看>>
2007年后,即将脱离单身
查看>>
當中文的OS + 英文的VS 2005 + SP1 = 中英混合的IDE
查看>>
Orphean WinForm Helper Patch 1
查看>>
Framework的设计与应用--基于Windows Forms的应用开发实践
查看>>
Inside ObjectBuilder 范例
查看>>
Inside ObjectBuilder Part 4
查看>>
Inside ObjectBuilder Part 2
查看>>