0

I am noticing a strange issue with respect to spring XML schemas.

I have a standalone java application which uses spring framework. As long as I run this application within eclipse, I do not face any issues. However, when I package this as a jar file (as described in this link), and execute the jar, I get the following exception:

Exception in thread "main" 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 [applicationContext.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1416)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)

I have the following entry in applicationContext.xml and it works fine inside eclipse:

<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.1.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

Any help is much appreciated.

I even tried changing http://www.springframework.org/schema/tx/spring-tx-3.1.xsd to classpath:/org/springframework/transaction/config/spring-tx-3.1.xsd but it did not help.

Community
  • 1
  • 1
saravana_pc
  • 2,607
  • 11
  • 42
  • 66
  • Did you see this: http://stackoverflow.com/questions/1937767/spring-3-0-unable-to-locate-spring-namespacehandler-for-xml-schema-namespace – kbdjockey Aug 08 '12 at 12:53
  • @kbdjockey - I do not have a WEB-INF/lib structure as it is just a standalone java application. – saravana_pc Aug 08 '12 at 13:10

1 Answers1

3

It looks like your application contains some jars, like spring-core-3.1.x (because its classes are being used), but it's missing spring-tx-3.1.x.RELEASE.jar (the one that holds Spring Transaction classes).

Luciano
  • 8,552
  • 5
  • 32
  • 56
  • when I package my application as a jar, all the dependency jars are exploded and packaged into my jar. (i.e.) myapp.jar contains all spring dependencies as class files within the package structure. I verified and noticed that the XSD files that are referred in applicationContext.xml are present in the right folders. – saravana_pc Aug 08 '12 at 13:14
  • So, your JARs are "unzipped" and everything is put together? That's a bad idea. You see, many Spring JARs contain a folder named META-INF (you can check it in Eclipse). Inside this folder there are three files named spring.handlers, spring.schemas and spring.tooling. These files have the same name on each jars, but contain different information. So if everything is put together, these are being overriden by each jar. – Luciano Aug 08 '12 at 13:32
  • Ok, that seems to make sense. But it is the maven assembly plugin which unzips the dependent jars when I create my jar. I now need to see how I can retain the dependencies as jars rather than they being exploded. – saravana_pc Aug 08 '12 at 13:35
  • Thanks for the tip, Maven shade plugin with "transformers configuration" should do the trick. – saravana_pc Aug 08 '12 at 14:47