Java 移动后出错<;mvc:注释驱动/>;:找不到元素';mvc:注释驱动的&x27;

Java 移动后出错<;mvc:注释驱动/>;:找不到元素';mvc:注释驱动的&x27;,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个dispatcher-servlet.xml和一个applicationContext.xml 我一直在做一些重构工作,我很感动 <mvc:annotation-driven/> <context:component-scan base-package="com.xxx"/> 我的applicationContext.xml如下所示: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns

我有一个dispatcher-servlet.xml和一个applicationContext.xml

我一直在做一些重构工作,我很感动

<mvc:annotation-driven/>
<context:component-scan base-package="com.xxx"/>
我的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: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>

我的dispatcher-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"
       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>

类路径:${systemTargetEnv}/app.properties
类路径:/build.properties
系统属性模式覆盖
我一直在进行重构,并将
dispatcherservlet.xml
移动到
applicationContext.xml

你不想那样做<代码>用于启用注释样式的MVC控制器,这些控制器必须位于
dispatcher servlet.xml
中。将
放入
applicationContext.xml
是毫无意义的,它将没有任何意义的效果

不过,我可能应该回答这个问题,答案是虽然您声明了
mvc
名称空间,但没有告诉Spring在哪里找到它的模式。加

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

applicationContext.xml

中的
schemaLocation
属性,谢谢您的回答-我已经移动了它,但是现在在上下文中出现了错误。我想我已经更新了模式。为了反映这一点,我修改了这个问题。我以为组件扫描应该在应用程序上下文中进行?!谢谢,我更新了我的上下文模式位置,现在我们又开始工作了。谢谢
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd