<mvc:argument-resolvers> 这里不允许

<mvc:argument-resolvers> Not allowed here

这是我的 spring- 上下文文件:

<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<beans:bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basename" value="classpath:i18n/messages" />
    <beans:property name="defaultEncoding" value="UTF-8" />
</beans:bean>

<annotation-driven/>
<resources mapping="/resources/**" location="WEB-INF/resources/" />
<context:component-scan base-package="com.softserve.edu.controller" />

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <ref bean="sortResolver"/>
        <ref bean="pageableResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>

<bean id="sortResolver" class="org.springframework.data.web.SortHandlerMethodArgumentResolver" />
<bean id="pageableResolver" class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
    <constructor-arg ref="sortResovler" />
</bean>
...

编译时我得到

Element 'mvc:annotation-driven' must have no character or element information item [children], because the type's content type is empty

为什么会出现这个错误以及如何让它工作? 我确定 和 的部分是错误的,但我不知道如何解决这个问题。

尝试将 schemaLocation 更改为 spring-mvc-3.2.xsd,应该可以。但是你必须使用 <bean class=""/> 标签来注册解析器。 Bean 引用不会那样工作

可能会尝试这样的事情:

<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <beans:bean id="sortResolver"
            class="org.springframework.data.web.SortHandlerMethodArgumentResolver" />
        <beans:bean
            class="org.springframework.data.web.PageableHandlerMethodArgumentResolver">
            <beans:constructor-arg ref="sortResolver" />
        </beans:bean>
    </mvc:argument-resolvers>
</mvc:annotation-driven>