1

I am getting below error when running my application on apache tomcat.

HTTP Status 500 - Servlet.init() for servlet spring threw exception

root cause

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 
Line 11 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid;
 nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

My spring-context.xml is this

            <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:cotext="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:beans="http://www.springframework.org/schema/beans" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                         http://www.springframework.org/schema/context
                         http://www.springframework.org/schema/context/spring-context-3.0.xsd
                         http://www.springframework.org/schema/mvc">

     <mvc:annotation-driven/>
     <cotext:component-scan base-package="springmvc"/>   

I've tried https://jira.springsource.org/browse/SPR-3372 with no luck.

please help.

2 Answers 2

1

Few things looks off to me:

1) You have to remove " http://java.sun.com/xml/ns/javaee" in xmlns attribute. I think this is the main problem here. "xmlns" attribute can't take multiple URIs according to spec: http://www.w3schools.com/xml/xml_namespaces.asp

2) Some XML libraries don't like the spaces in the beginning of XML file in front of (in particular Eclipse will complain)

3) xsi:schemaLocation value is missing location URI for mvc. It should probably look like this:

 xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/mvc
               http://www.springframework.org/schema/context/spring-mvc-3.0.xsd">

You can as well remove extra "beans" declaration as previous answer suggests, unless you really want to use "beans" namespace prefix for some reason.

Sign up to request clarification or add additional context in comments.

2 Comments

In your xml snipped there are spaces in the first line: " <?xml version="1.0" encoding="UTF-8"?>" This is incorrect according to XML 1.0 spec: "The XML declaration typically appears as the first line in an XML document. The XML declaration is not required, however, if used it must be the first line in the document and no other content or white space can precede it." msdn.microsoft.com/en-us/library/ms256048.aspx
thanks for clarification. these spaces were added to format my question before posting here.
0

You have repeating entry of xmlns:beans="http://www.springframework.org/schema/beans" in your XML header. Remove one instance of it and try as below:

<beans xmlns="http://www.springframework.org/schema/beans http://java.sun.com/xml/ns/javaee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:cotext="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd
               http://www.springframework.org/schema/mvc">

      <mvc:annotation-driven/>
      <cotext:component-scan base-package="springmvc"/>   

1 Comment

@Muhammad Is that your entire file or you have more details inside as I don't see beans tag being closed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.