这是我的spring-context文件:
<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
为什么会出现此错误以及如何使此功能生效? 我确定那部分有错,但我不知道如何解决这个问题。
答案 0 :(得分:4)
尝试将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>