Announcement Announcement Module
Collapse
No announcement yet.
XmlBeanDefinitionStoreException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XmlBeanDefinitionStoreException

    I am a newbie in spring framework. I am trying my very first spring example which is given in Spring in action 3rd edition.
    When i am trying to load the xml context file as follows in my main function
    #
    ApplicationContext ctx = new ClassPathXmlApplicationContext("ContextFile.xml");
    #
    I am getting the following error ..

    Nov 3, 2012 11:34:57 PM org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@ab50cd: startup date [Sat Nov 03 23:34:57 IST 2012]; root of context hierarchy
    Nov 3, 2012 11:34:57 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [ContextFile.xml]
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 1 in XML document from class path resource [ContextFile.xml] is invalid; nested exception is org.xml.sax.SAXParseException: White space is required before the encoding pseudo attribute in the XML declaration.
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:302)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:127)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:93)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplic ationContext.obtainFreshBeanFactory(AbstractApplic ationContext.java:527)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:441)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
    at Spring.SpringDI.PerformerTest.main(PerformerTest.j ava:9)
    Caused by: org.xml.sax.SAXParseException: White space is required before the encoding pseudo attribute in the XML declaration.
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.fatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorRe porter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner .reportFatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner .scanXMLDeclOrTextDecl(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanXMLDeclOrTextDecl(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl$XMLDeclDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocum entScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocum entLoader.loadDocument(DefaultDocumentLoader.java: 75)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:388)
    ... 14 more


    Can anyone let me know the reason for the error and its solution pl.

    Thanks in advance..

  • #2
    Could you show us the first lines content of ContextFile.xml?

    Comment


    • #3
      And please use [ code][/code ] tags when posting code/xml/stacktraces that way it remains readable.

      Also the stacktrace is pretty clear on the error..

      Code:
       org.xml.sax.SAXParseException: White space is required before the encoding pseudo attribute in the XML declaration
      SO you probably forgot a whitespace somewhere...

      Comment

      Working...
      X