Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring v3 no declaration can be found for element 'mvc:resources'

Currently Running

Tomcat: v6

Spring Tools Suite: v2.7.2

Spring Framework: spring-webmvc-3.0.5

Servlet XML

 <?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:mvc="http://www.springframework.org/schema/mvc"         xmlns:context="http://www.springframework.org/schema/context"         xsi:schemaLocation="           http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd           http://www.springframework.org/schema/mvc/spring-mvc           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd           http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context-3.0.xsd">        <mvc:annotation-driven />        <mvc:resources mapping="/resources/**" location="/resources" />        <context:component-scan base-package="com.app.mvc" />   </beans> 

web.xml partial code

<servlet-mapping>     <servlet-name>duckapp</servlet-name>     <url-pattern>/</url-pattern> </servlet-mapping> 

Servlet Purpose

web.xml maps all urls to the servlet with the exception of mvc:resources mapping static files.

Bugs

  • cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'. app-servlet.xml /app/www/WEB-INF

  • cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'. app-servlet.xml /app/www/WEB-INF

Known Issues

  • http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd doesn't contain the element resource

  • If replaced by http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd still doesn't work and may not be working according to jar files of spring 3.05

  • mvc:resources appeared in spring v3.0.4, but has no new xsd

Question

How can I fix the compile errors to get mvc:resources working correctly?

I've been digging around 2 hours for this, no solid answer yet...

like image 549
Luc Laverdure Avatar asked Sep 15 '11 19:09

Luc Laverdure


1 Answers

In your spring context xml mvc namespace url should match url in schemaLocation. Something like this:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:mvc="http://www.springframework.org/schema/mvc"        xsi:schemaLocation="          http://www.springframework.org/schema/mvc          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

This is a standard XML namespace declaration. The namespace url is sort of an unique id, which is then mapped to the actual schema location in xsi:schemaLocation.

like image 98
Eugene Kuleshov Avatar answered Oct 13 '22 14:10

Eugene Kuleshov