I have a dispatcher-servlet.xml and an applicationContext.xml.
I have been doing some refactoring, and moved
<mvc:annotation-driven/>
<context:component-scan base-package="com.xxx"/>
from dispatcher-servlet.xml to applicationContext.xml.
I now get this error:
2012-01-26 10:34:36.434:WARN::Nested in org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/applicationContext.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 'context:component-scan'.:
org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
My applicationContext.xml looks like this:
<?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:p="http://www.springframework.org/schema/p"
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd"
xmlns:context="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
>
<mvc:annotation-driven/>
<context:component-scan base-package="com.xxx"/>
<bean id="templateErrorListener"
class="com.stringtemplate.log.Slf4jStringTemplateErrorListener"/>
<bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
p:config-location="/WEB-INF/ehcache.xml"/>
<ehcache:annotation-driven cache-manager="ehCacheManager"/>
</beans>
and my dispatcher-servlet.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="mediaTypes">
<map>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
</list>
</property>
<property name="ignoreAcceptHeader" value="true"/>
</bean>
<bean class="com.stringtemplate.StringTemplateViewResolver">
<property name="templateErrorListener" ref="templateErrorListener"/>
<property name="templateRoot" value="/WEB-INF/templates/"/>
<property name="order" value="2"/>
</bean>
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="order" value="3"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="formHttpMessageConverter"/>
<ref bean="stringHttpMessageConverter"/>
</list>
</property>
</bean>
<bean id="formHttpMessageConverter "
class="org.springframework.http.converter.FormHttpMessageConverter "/>
<bean id="stringHttpMessageConverter "
class="org.springframework.http.converter.StringHttpMessageConverter "/>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:${systemTargetEnv}/app.properties</value>
<value>classpath:/build.properties</value>
</list>
</property>
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
</bean>
</beans>
You don’t want to do that.
<mvc:annotation-driven/>is there to enable annotation-style MVC controllers, and those controllers must reside indispatcher-servlet.xml. Putting<mvc:annotation-driven/>inapplicationContext.xmlis pointless, it will have no meaningful effect.I should probably answer the question, though, amnd the answer is that while you’ve declared the
mvcnamespace, you did not tell Spring where to find the schema for it. Addto the
schemaLocationattribute inapplicationContext.xml