Unable to locate Spring NamespaceHandler for XML schema namespace
原文地址:http://www.baeldung.com/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace
- 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
<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
Offending resource: class path resource
The solution is straightforward – the spring-security-config dependency is missing from the classpath of the project: ? 1 2 3 4 5
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
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
Offending resource: ServletContext resource
The solution is similar – the spring-aop jar needs to be added to the classpath of the project: ? 1 2 3 4 5
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
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
Offending resource: class path resource
The missing dependency here is spring-tx: ? 1 2 3 4 5
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
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
Offending resource: class path resource
In this case, the missing dependency is spring-mvc: ? 1 2 3 4 5
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.