Shamik
Shamik

Reputation: 1731

Unable to locate Spring NamespaceHandler for XML schema namespace issue

I'm having this weird problem of " Unable to locate Spring NamespaceHandler for XML schema namespace". I'm referencing GATE namespace in my spring application context. It's an executable jar in which a java class instantiates the spring application context. It works fine when I'm testing it in my local machine through eclipse. But, the problem appears when I try to run it as an executable jar with a java main class.

Here's the exception.


org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://gate.ac.uk/ns/spring]
Offending resource: class path resource [applicationContext.xml]

As you can see, it's complaining about gate namespace.

Here's the application context entry.


<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:gate="http://gate.ac.uk/ns/spring"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
       http://gate.ac.uk/ns/spring http://gate.ac.uk/ns/spring.xsd">

The schema is accessible and is valid.

The executable jar has gate dependent jar files included. Here's the pom file entry for gate


<dependency>
            <groupId>gate</groupId>
            <artifactId>gate</artifactId>
            <version>5.1</version>
        </dependency>
        <dependency>
            <groupId>gate</groupId>
            <artifactId>gate-asm</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>gate</groupId>
            <artifactId>gate-compiler-jdt</artifactId>
            <version>1.0</version>
        </dependency>

Here's the java code snippet


try{
    AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
        this.processor = (TestProcessor) ctx.getBean("testProcessor");
   }catch (Exception ex) {
    ex.printStackTrace();
   }

Here's the Gate documentation reference.

http://gate.ac.uk/releases/gate-5.0-beta1-build3048-ALL/doc/tao/splitch3.html#x5-900003.27

Not sure what's going wrong, any pointers will be highly appreciated.

Thanks

Upvotes: 1

Views: 2600

Answers (1)

Biju Kunjummen
Biju Kunjummen

Reputation: 49935

The namespacehandler for the gate custom namespace will be specified in the jar file which this application has provided (gate.jar?), if you look into the jar file you should see a META-INF/spring.handlers file with an entry of the following type:

http://gate.ac.uk/ns/spring=*NamespaceHandler

This is the handler that your program is not able to find at startup time. Your classpath may be off in the main program or if you have used something to combine the jars into a single jar(uber jar) then the merging of META-INF/spring.handlers file across different jar files could have got messed up, there are good workarounds available for that if you created a uber jar though.

Upvotes: 2

Related Questions