1

I am getting the following error in my logs:

Caused by: 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'.

This shows up when I try to view my application in the browser:

Error 500: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet

Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
    id="WebApp_ID"
    version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>MyAwesomeApp</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

Here is my spring-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">
    <context:component-scan
        base-package="org.myapp.controllers" />
    <bean
        id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property
            name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property
            name="prefix"
            value="/WEB-INF/views/" />
        <property
            name="suffix"
            value=".jsp" />
    </bean>
    <mvc:resources
        mapping="/resources/**"
        location="/resources/" />
</beans>

What am I doing wrong? If I take out the <mvc:resources tag, my app shows up, but its CSS doesn't load.

Edit: maybe I've got some other issues, because now I'm not getting that error, though my app doesn't show up--I just get a 404. I do get this in the log now, which looks promising:

SimpleUrlHand I org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'

Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222

2 Answers2

2

You did a mistake in namespaces declaration in spring-servlet.xml. Please change:

xsi:schemaLocation="
(...)
http://www.springframework.org/schema/mvc/spring-mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
(...)"

to:

xsi:schemaLocation="
(...)
http://www.springframework.org/schema/mvc/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
(...)"

Since you declared

xmlns:mvc="http://www.springframework.org/schema/mvc"

not (...)/schema/spring-mvc.

omnomnom
  • 8,911
  • 4
  • 41
  • 50
0

I ended up following this tutorial, creating a new Spring Template Project using the Spring MVC Project template. I then created an EAR (new Enterprise Application Project in Rational Application Developer) that included my new Spring MVC project. Deployed the EAR to my WAS 7, all is fine. I put my CSS and JavaScript files in src/main/webapp/resources and link to them in my views with resources/stylesheet.css. The template project came with a resources directory already set up.

I did notice that its context file referenced http://www.springframework.org/schema/mvc in both the xmlns and the xsi:schemaLocation, not http://www.springframework.org/schema/mvc/spring-mvc as I did in the xsi:schemaLocation, so I think Piotrek's answer is probably correct.

Community
  • 1
  • 1
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222