Results 1 to 7 of 7

Thread: <mvc:resources mapping="/resources/**" is invalid??

  1. #1
    Join Date
    Jul 2008
    Posts
    182

    Default <mvc:resources mapping="/resources/**" is invalid??

    Hello,

    I found this shouldn't be happened, as this example is one of the spring examples I downloaded from spring website.

    The example is spring 3 with maven build.

    Here is the error I got when during the deployment process:

    [#|2011-06-20T21:20:08.542+1000|INFO|glassfish3.1|javax.enter prise.system.std.com.sun.enterprise.server.logging |_ThreadID=93;_ThreadName=Thread-1;|ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
    org.springframework.beans.factory.xml.XmlBeanDefin itionStoreException: Line 26 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 'mvc:resources'.
    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:143)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:124)
    at org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:93)
    at
    ....
    Here is the WEB-INF/spring/appServlet/servlet-context.xml file:

    <?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="org.springframework.samples.mvc.basic" />

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <!-- Forwards requests to the "/" resource to the "welcome" view -->
    <mvc:view-controller path="/" view-name="welcome"/>

    <!-- Configures Handler Interceptors -->
    <mvc:interceptors>
    <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
    <bean class="org.springframework.web.servlet.i18n.Locale ChangeInterceptor" />
    </mvc:interceptors>

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

    <!-- Saves a locale change using a cookie -->
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.Cookie LocaleResolver" />

    <!-- Application Message Bundle -->
    <bean id="messageSource" class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/messages/messages" />
    <property name="cacheSeconds" value="0" />
    </bean>

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
    </bean>

    </beans>
    Please see attachment for a full trace.
    Your help is very much appreciated.
    Thanks
    Sam
    Attached Files Attached Files
    Last edited by samsam007; Jun 20th, 2011 at 06:47 AM.

  2. #2
    Join Date
    Jul 2008
    Posts
    182

    Default

    I also attach this example project here for reference.

    Thank you in advance for any suggestion and help.
    Sam
    Attached Files Attached Files

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    You situation is weird, it should work

    BTW when I create with STS 2.6.1 a Spring MVC Template project by default the follow is created

    Code:
    <?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"
    	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">
    
    	<!-- 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/" />
    ...
    With which Spring version you are working?

    of course I could change
    Code:
    xmlns="http://www.springframework.org/schema/mvc"
    to
    Code:
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  4. #4
    Join Date
    Jul 2008
    Posts
    182

    Default

    Hi Dr,

    Thank you for the reply again.
    As my pom.xml file indicated, it is using 3.0.2-Release:
    <spring.version>3.0.2.RELEASE</spring.version>

    Thanks
    Sam

  5. #5
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    what happen if you use
    Code:
    <spring.version>3.0.5.RELEASE</spring.version>
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  6. #6
    Join Date
    Jul 2008
    Posts
    182

    Default

    3.0.5-Release works with commandline compilation
    eg.
    mvn compile war:war

    this works.

    But in Eclipse, I got the following error:

    The import org.springframework.web cannot be resolved

    This didn't happen with 3.0.2 release.
    I have select Project->clean, but the error still persist.


    Thanks & best regards
    Sam

  7. #7
    Join Date
    Jul 2008
    Posts
    182

    Default Resolved

    After added Spring 3.0.5-Release jar to the build-path, the error in Eclipse is gone.

    Thank you very much for the great help
    You have a lovely day
    Sam

Posting Permissions

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