4

I know this is a duplicate and you people are gonna chide me for it, but I didn't get a proper solution after reading all the posts.
I am trying to build a Spring Template application in Spring Source Tool Suite. I am getting the following error.

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'resources'.

My root-context.xml is like this:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

</beans>

Please let me know if there is a jar file missing in my application.
These are the only jar files I have in my application:
displaytag-1.0-b3.jar, spring-2.0.6.jar, spring-asm-3.0.3.RELEASE.jar, spring-beans-3.0.3.RELEASE.jar, spring-context-3.0.3.RELEASE.jar, spring-core-3.0.3.RELEASE.jar, spring-expression-3.0.3.RELEASE.jar, spring-hibernate3-2.0.8.jar, spring-web-3.0.3.RELEASE.jar & spring-webmvc-3.0.3.RELEASE.jar

Here is my servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        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">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.foo.controller" />



</beans:beans>

Please help...it's really annoying.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Freakyuser
  • 2,774
  • 17
  • 45
  • 72
  • Why didn't you post the actual XML, including the "resources" element? – Marko Topolnik Nov 30 '12 at 13:05
  • @MarkoTopolnik I really don't understand which xml file you are talking about. This context.xml is what I have got. With this file in place there is the error which I have mentioned. – Freakyuser Nov 30 '12 at 13:09
  • The error is about an element "`resources`", which presumably occurs in your XML. – Marko Topolnik Nov 30 '12 at 13:11
  • @MarkoTopolnik Thanks for the quick response. There is no such element in my xml, you spotted it. But I don't know if there is such an element to be added to the xml file. Can you please guide me? – Freakyuser Nov 30 '12 at 13:15
  • Show your /WEB-INF/spring/appServlet/servlet-context.xml file. – Aleksandr M Nov 30 '12 at 13:17
  • The problem report complains about an **existing** element "resources", not a missing one. I don't see how you can get that error without an actual element. – Marko Topolnik Nov 30 '12 at 13:18
  • @AleksandrM Thanks. Here it is – Freakyuser Nov 30 '12 at 13:21
  • Please post the relevant XML file, up to line 16, **in your question** by editing it. Not in a comment like this. – Marko Topolnik Nov 30 '12 at 13:23
  • possible duplicate of [Spring v3 no declaration can be found for element 'mvc:resources'](http://stackoverflow.com/questions/7436224/spring-v3-no-declaration-can-be-found-for-element-mvcresources) – Marko Topolnik Nov 30 '12 at 13:24
  • You have declared namespace prefixes that you fail to use for the elements. It's ``, as seen in the duplicate question I linked to above. The same goes for your other elements. – Marko Topolnik Nov 30 '12 at 13:31
  • @MarkoTopolnik Sorry for being a dumbhead, I don't understand the above comment. Where do I have to add the ? – Freakyuser Nov 30 '12 at 13:37
  • @MarkoTopolnik Pressure is building on my head. Please explain the last comment. The error I have made may be silly, but I am unable to spot it. – Freakyuser Nov 30 '12 at 13:48
  • Your XML is correct, but your Spring version is too old... – Ian Roberts Nov 30 '12 at 13:52

1 Answers1

11

Your XML is fine, but according to this comment on a SpringSource blog post about Spring MVC 3

The <mvc:resources/> tag is a new feature coming in Spring Framework 3.0.4

Your application uses Spring 3.0.3, so you need to upgrade to 3.0.4 or later to be able to use the resources tag.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • Thank you for an answer. I tried changing the tag to but still I am getting an error. – Freakyuser Nov 30 '12 at 13:57
  • Robert Now should I upgrade my jar files to spring 3.0.4 or change any tag? Please help... – Freakyuser Nov 30 '12 at 13:58
  • 2
    @Freakyuser your XML was correct in the first place, you are using an XML element with the local name `resources` and the namespace URI `http://www.springframework.org/schema/mvc` (using that as the default namespace of your XML file instead of the more usual approach of using the "beans" namespace as the default and mapping the MVC namespace to a prefix, but from an XML point of view both approaches are equivalent). But 3.0.3 does not support this element at all, you must upgrade in order to make it work. – Ian Roberts Nov 30 '12 at 15:03