• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Context xml file - cvc-complex-type.2.4.c:

 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am new to Spring and am trying to get a simple tutorial using JSP page running.

I am getting the following error in one of the context file I am using (under webContent->Web-INF folder). Following is the error message

"cvc-complex-type.2.4.c: The matching wildcard is string:but no declaration can be found for the element mvc:annotation-driven"


Here is the XML file

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you didn't fully bring in the mvc namespace. And you have aop namespace partly in there too. xml namespaces are about xml, and Spring creates a number of xml namespaces. You need two parts in the header to add a namespace.

The first part like this

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

sets the prefix "mvc" to the key string of "http://www.springframework.org/schema/mvc"

That key is used in the xsi:schemaLocation attribute, where you need the key and the .xsd, like a key value pair.

If you look at your schemaLocation you can see each pair. You have one for beans tags
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

You have one for context, and one for aop.

To fix it, you can just change the schemaLocation parts in the string that points to aops xsd file and where ever you see the text "aop" replace it with "mvc"

So you end up having



Mark
 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot. It has resolved the compile issue. let me try to run the application.
 
Asvin Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

Me too new to Spring and I'm trying to run a sample code from a tutorial. This is my applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"
default-lazy-init="false">

<!-- This required so that Spring can recognize our annotated beans -->
<context:annotation-config />

<!-- This required so that Spring can recognize certain annotations,
For example @Controller and @Service. Make sure you set the correct base-package
-->
<context:component-scan base-package="org.krams.tutorial" />

<!--
This is responsible for automatically converting our custom POJO to JSON.
Make sure you have Jackson in your classpath
-->
<mvc:annotation-driven />

</beans>


I get the error message cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
 
Asvin Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it. I changed the http://www.springframework.org/schema/mvc/spring-mvc.3.1.xsd to http://www.springframework.org/schema/mvc/spring-mvc.xsd and it worked.

Not sure if I'm lucky. I see the jars for 3.0.5, so just tried without specifying the version.

Thanks,
Asvin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic