Announcement Announcement Module
Collapse
No announcement yet.
cvc-elt.1: Cannot find the declaration of element 'beans' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • cvc-elt.1: Cannot find the declaration of element 'beans'

    Hi, Im migrating from Spring 1.2.6 to Spring 2.0.4 and this exception is thrown when I start the client

    Code:
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from class path resource [Spring-CommonHttpInvoker.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
    	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
    	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
    	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
    	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
    	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
    	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
    	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
    	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
    	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:351)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:280)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)
    	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:100)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:313)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    ...
    The Spring-CommonHttpInvoker.xml file is

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    
    <!-- ::::::::::::: COMMON BEANS FOR HTTPINVOKER :::::::::::::::::: -->
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    Beans declarations...
    
    </beans>
    Does anyone knows why and how can I resolve it?
    Thanks!!

    Leandro

  • #2
    Do you still have the spring 1.2.6 jar file on your classpath?

    Comment


    • #3
      Originally posted by Mark Fisher View Post
      Do you still have the spring 1.2.6 jar file on your classpath?
      No, I have the Spring.jar and other jars, but not the 1.2.6 version.

      Comment


      • #4
        Same issue

        I have a similar issue also with Spring 2.0.4 (and now I tried also 2.0.5). I'm new to spring and I tried my first example to instantiate a very simple bean.

        Here my example (it was just for testing purposes):

        -------------------------------------------------
        <?xml version="1.0" encoding="UTF-8" ?>
        <beans>
        <bean id="bean" class="com.project.testBean" />
        </beans>
        -------------------------------------------------

        FileSystemResource resource = new FileSystemResource("C:\\Users\\Stefan\\IdeaProject s\\Test\\Framework\\classes\\com\\project\\bean.xm l");

        System.out.println(resource.toString());
        System.out.println(resource.exists());
        BeanFactory factory = new XmlBeanFactory(resource);
        Object bean = factory.getBean("testBean");

        The result output:

        file [C:\Users\Stefan\IdeaProjects\Test\Framework\classe s\com\project\bean.xml]
        true
        11.05.2007 23:35:30 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
        INFO: Loading XML bean definitions from file [C:\Users\Stefan\IdeaProjects\Test\Framework\classe s\com\project\bean.xml]
        Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 2 in XML document from file [C:\Users\Stefan\IdeaProjects\Test\Framework\classe s\com\project\bean.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
        Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandl erWrapper.createSAXParseException(ErrorHandlerWrap per.java:236)
        ...

        So the file exists and also the <beans> seems to be available.

        Has anybody an idea what is going wrong here?

        Comment


        • #5
          You need the XSD header, such as:
          Code:
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.springframework.org/schema/beans      
                         http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
          
             <bean ... />
          
          </beans>

          Comment


          • #6
            reference beans locally

            how can I reference xsi:schemalocation to a local file that is in the spring.jar file
            I want to use my application without internet access and when i try to use it
            it throws that exception. the manual does not explain how to do that

            Comment


            • #7
              hI,
              Earlier me also got the same error because of XSD problem.

              Put the XSD as it is in the Spring.jar file.

              If you open up the spring.jar, there is a spring.schemas file in META-INF folder. There you can find the required schema definitions that will run without the need of Internet connection.

              Comment


              • #8
                Originally posted by aldomedina View Post
                how can I reference xsi:schemalocation to a local file that is in the spring.jar file
                I want to use my application without internet access and when i try to use it
                it throws that exception. the manual does not explain how to do that
                To reference a schema that is in your local jar file include the following schema locations definition in your root beans attributes:

                Code:
                xsi:schemaLocation="http://www.springframework.org/schema/beans
                                            classpath:/org/springframework/beans/factory/xml/spring-beans-2.5.xsd
                                            http://www.springframework.org/schema/util
                                            classpath:/org/springframework/beans/factory/xml/spring-util-2.5.xsd"

                Comment


                • #9
                  Originally posted by sweetfa View Post
                  To reference a schema that is in your local jar file include the following schema locations definition in your root beans attributes:

                  Code:
                  xsi:schemaLocation="http://www.springframework.org/schema/beans
                                              classpath:/org/springframework/beans/factory/xml/spring-beans-2.5.xsd
                                              http://www.springframework.org/schema/util
                                              classpath:/org/springframework/beans/factory/xml/spring-util-2.5.xsd"

                  This answer is correct, but not the same as different versions. When the 2.0 version of the time to this:
                  <?xml version="1.0" encoding="utf-8"?>
                  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
                  <beans>

                  Comment

                  Working...
                  X