Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Using the container in a standalone app, with XML definitions

  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Default Using the container in a standalone app, with XML definitions

    Hi

    OK - firstly, what I want to do is to run Spring within my desktop application. I was to use the Spring AOP for a few things, and plan on using other features later on..

    To get the AOP working, I presume I need to get an ApplicationContext, and this is where I'm having problems.

    I tried using the FileSystemXMLApplicationContext, but when I try to read the config file it gives this error:
    Exception in thread "main" org.springframework.beans.FatalBeanException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@ 2ce908] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.


    The thing is that I'm using Java 1.5, and also have Xerces in my classpath - so this error makes no sense to me.

    Does anyone have any ideas why this would be happening?

    Any help would be greatly appreciated.

    Alternatively I was thinking about using the StaticApplicationContext for the time being, and adding in the AOP stuff to that - is that a terrible idea?

    Thanks!
    James

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    I would recommend ClasspathXmlApplicationContext. Loading files from the file system is very fragile.

    Spring uses the regular JAXP DOM API. If it can't start up due to an XML error, this is presumably affecting all XML parsing through this standard API, and indicates some kind of misconfiguration. Are you using Spring 2.0M1, or 1.2.6?
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Jan 2006
    Posts
    4

    Smile

    Thanks Rod -

    I'll change over to the Classpath one so.

    I found that the problem was due to an old version of Xerces that was in my project's classpath.

    But it works well now - quite easy too.

    Looking forward to getting the AOP stuff completed and then seeing what else Spring can do for me desktop app.

    All thanks to that talk you did in Cork last September!
    James

  4. #4
    Join Date
    Apr 2006
    Location
    Montreal, Canada
    Posts
    178

    Default Similar problem...

    Quote Originally Posted by Rod Johnson
    I would recommend ClasspathXmlApplicationContext. Loading files from the file system is very fragile.

    Spring uses the regular JAXP DOM API. If it can't start up due to an XML error, this is presumably affecting all XML parsing through this standard API, and indicates some kind of misconfiguration. Are you using Spring 2.0M1, or 1.2.6?
    I'm afraid I'm running into a similar problem while executing some unit tests. The tests are running in a 1.3.1 JVM with Xerces 2.8.0 in the classpath. I'm using a Spring 2.0 RC1 ClasspathXmlApplicationContext to load a XSD-based file. Here is the stack trace:

    Code:
    org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [com/auchan/core/context/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unable to validate using XSD: Your JAXP provider [org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@121f1d] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unable to validate using XSD: Your JAXP provider [org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@121f1d] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:90)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:62)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:385)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:340)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:315)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:168)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:278)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
    The strange thing is that it's the Crimson parser that's picked up and not the Xerces one. Is there a configuration parameter I'm missing somewhere?

    Thanks,
    GB

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    The JDK might come with an old version of the xml parser which will used automatically. IIRC, one solution would be to put the XML libraries in JDK endorsed folder (JAVA_HOME/jre/lib/ext) - this way the XML libraries will be automatically picked up and used instead of the ones supplied with the VM.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Apr 2006
    Location
    Montreal, Canada
    Posts
    178

    Default

    Thanks for your answer, Costin. I finally solved the problem by including a META-INF/services/javax.xml.parsers.DocumentBuilderFactory file with the Xerces implementation class name inside. Works like a charm finally

  7. #7
    Join Date
    May 2006
    Posts
    7

    Default

    Hi everyone,

    I am having a similar problem to the above however I am trying to deploy my application as a war file. The error I get is:

    Code:
    org.springframework.beans.factory.BeanDefinitionStoreException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@3a835d] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
    The strange thing is that according to the exception message, xerces is used as a provider.
    Xerces version is 2.8.0 and JDK is 1.4.2.11

    Any ideas?

    Thanks,

    EP

    PS. Forum search seams to exclude text in CODE tags(???). Couldn't find this thread from the forum search.

  8. #8
    Join Date
    May 2006
    Posts
    7

    Default

    This is now solved. It was as usual my mistake since I didn't notice that maven was adding xerces-1.2.3 in my classpath as a transitive dependency of commons-jxpath.

  9. #9
    Join Date
    Apr 2006
    Location
    Oslo, Norway
    Posts
    23

    Default Annoying

    This is quite annoying when configuring the ApplicationContext in your unit tests. Common requirement is that some of the applicationContext usually is located outside the classpath, most often WEB-INF/applicationContext-whatever.xml. I see the Petclinic example has solved this by duplicating the applicationContext files and storing them in the test source folder (example applicationContext-hibernate.xml). This I feel is a bad pattern and a swell DRY

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,626

    Default

    Well instead of loading them from the classpath load the from the filesystem, or place your configuration files in your classpath. (We chose the latter one). For the first prefix your configuration files in your testclass with file:/fullpath/context.xml and you should be good to go.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •