当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

Unable to locate Spring NamespaceHandler for XML schema namespace

发表于: 2014-09-04   作者:矮蛋蛋   来源:转载   浏览次数:
摘要: 原文地址: 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 –
原文地址: 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.

Unable to locate Spring NamespaceHandler for XML schema namespace

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
目前做的项目,其中一个模块是由我负责,采用hibernate和spring,没有使用struts。是一个socket 服
目前做的项目,其中一个模块是由我负责,采用hibernate和spring,没有使用struts。是一个socket 服
目前做的项目,其中一个模块是由我负责,采用hibernate和spring,没有使用struts。是一个socket 服
Key Words Spring 3.0 Apache CXF 2.X.X 昨日,在原本应用中添加了关于webService的调用,使用了Apa
我用maven建立的struts2项目,由于struts.xml的文件不止一个,所以我不想将它直接放在 resource 目
在使用eclipse 运行 maven install的时候,出现这个错误: [ERROR] Unable to locate the Javac Com
转:http://www.saptechnical.com/Tutorials/XI/XMLPayload/Index.htm There are situations where a
原文地址:http://www.cnblogs.com/jifeng/archive/2011/09/14/2176599.html 在很多情况下,我们需
上一篇文章"XML Schema检验XML文档结构"中,简单介绍了XML Schema及其写法,这篇主要针对java开发者
1. XML Schema简介 XML Schema(也称作XML Schema Definition),它用于检验XML文档的结构,是DTD文
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号