This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes Error in Context xml file - cvc-complex-type.2.4.c: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Error in Context xml file - cvc-complex-type.2.4.c: " Watch "Error in Context xml file - cvc-complex-type.2.4.c: " New topic
Author

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

nitinram agarwal
Ranch Hand

Joined: Jan 29, 2009
Posts: 83
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
nitinram agarwal
Ranch Hand

Joined: Jan 29, 2009
Posts: 83
thanks a lot. It has resolved the compile issue. let me try to run the application.
Asvin Kumar
Greenhorn

Joined: Mar 01, 2010
Posts: 13

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

Joined: Mar 01, 2010
Posts: 13
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in Context xml file - cvc-complex-type.2.4.c:
 
Similar Threads
Spring security - Need to secure methods - getting error
AOP Not working with Spring 3 MVC application
The matching wildcard is strict, but no declaration can be found for element 'context:annotation'
Including more than one controller having used it with sequence but error
Spring Integration with Drools