1

I am getting the following error when trying to access my pages using Spring MVC, addMinutes.jsp & hello.jsp. I can only access the root localhost, but if I navigate to a page, I get this error:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/config/servlet-config.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:annotation-driven'.

I've searched online and I think my xml="" links are probably wrong, but I got this straight from the pluralsight.com tutorial. I'm new to JAVA MVC so this is foreign to me. Any help would be appreciated.

Here is my servlet-config.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:context="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-2.0.xsd
                            http://www.springframework.org/schema/aop
                            http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

        <mvc:annotation-driven/>
        <context:component-scan base-package="com.pluralsight.controller"></context:component-scan>

        <!--
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean>
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>-->

            <bean class="org.springframework.web.servlet.view.InteralResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
    </beans>

Here is my web.xml

   <?xml version="1.0" encoding="UTF-8"?>
<web-app 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">

    <servlet>
        <servlet-name>fitTrackerServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/servlet-config.xml</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>


  <display-name>Archetype Created Web Application</display-name>
</web-app>
1
  • 1
    Learn about XML and what it means and what is required to declare a namespace. Commented Jan 27, 2014 at 19:53

3 Answers 3

1

Add the mvc and context schema locations to the beans section in the application context 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"        
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-2.0.xsd                       http://www.springframework.org/schema/aop
                          http://www.springframework.org/schema/aop/spring-aop
                          http://www.springframework.org/schema/mvc
                          http://www.springframework.org/schema/mvc/spring-mvc.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context.xsd">
Sign up to request clarification or add additional context in comments.

4 Comments

With these changes, I get three errors: no declaration found for context:component-scan, p:prefix not bound to bean, and Multiple annotations found at this line: - schema_reference.4: Failed to read schema document 'springframework.org/schema mvc/spring-mvc-2.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
also missing is the context namespace schema location - see update
@C.Coggins You really should try to understand the problem at hand and not resort to some copy/paste frenzy. For every namespace declaration you'll need to specify a location. You need to see if everything checks out.
@Bart, yes I could spend the next month trying to understand these xml errors, or I can simply put in the correct xml address per the tutorial, learn what the tutorial teaches, then expand onto bigger topics. If you're learning advanced math, you have to learn to count to 10 before you start learning about sin, tangents, etc...
0

How about this, basically its missing some namespaces xmlns:p="http://www.springframework.org/schema/p"

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

    <mvc:annotation-driven />
    <context:component-scan base-package="com.pluralsight.controller"></context:component-scan>


    <bean
        class="org.springframework.web.servlet.view.InteralResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
</beans>

Comments

0

Here's a working header template for your spring configuration:

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

Also make sure you are running a recent version of Spring >= 3 (otherwise the mvc and p-namespaces will not work) and that you have all the necessary Spring JARs in your classpath.

If you need to edit Spring configuration files often, installing Spring Tool Suite (STS) is a good help, since it has templates and the hugely useful 'namespaces' tab for configuring the necessary XML namespaces in Spring config files.

Also spending a few hours learning XML wouldn't hurt.

Comments

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.