在dispatcher.xml中不建议使用DefaultAnnotationHandlerMapping [英] DefaultAnnotationHandlerMapping is deprecated in dispatcher.xml
问题描述
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter和 mvc-dispatcher.xml中的org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping错误.为什么会这样呢? 请帮我吗?
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter is deprecated and org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping error in mvc-dispatcher.xml. Why could it be ? please help mee ?
如下所示的代码
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="saveGeoJSON.html">HspatialController</prop>
</props>
</property>
</bean>
DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter是删除线
DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter is strikethrough
推荐答案
如果使用的是Spring 3.1和更高版本,则应将这些类替换为RequestMappingHandlerMapping
和RequestMappingHandlerAdapter
.
You should replace those classes by RequestMappingHandlerMapping
and RequestMappingHandlerAdapter
if you are using Spring 3.1 and higher.
If you check the Spring 3.1 reference documentation, you'll see why those classes have been deprecated :
Spring 3.1引入了一组新的处理支持类 带注释的控制器的请求:
Spring 3.1 introduces a new set of support classes for processing requests with annotated controllers:
RequestMappingHandlerMapping
RequestMappingHandlerMapping
RequestMappingHandlerAdapter
RequestMappingHandlerAdapter
ExceptionHandlerExceptionResolver
ExceptionHandlerExceptionResolver
这些类替代了现有的类:
These classes are a replacement for the existing:
DefaultAnnotationHandlerMapping
DefaultAnnotationHandlerMapping
AnnotationMethodHandlerAdapter
AnnotationMethodHandlerAdapter
AnnotationMethodHandlerExceptionResolver
AnnotationMethodHandlerExceptionResolver
根据许多要求,开发了新类 批注控制器支持的类更具可定制性,并为 扩大.以前,您可以配置带有注释的自定义 控制器方法参数解析器,带有新的支持类 可以针对任何受支持的方法参数定制处理,或者 返回值类型.
The new classes were developed in response to many requests to make annotation controller support classes more customizable and open for extension. Whereas previously you could configure a custom annotated controller method argument resolver, with the new support classes you can customize the processing for any supported method argument or return value type.
第二个显着区别是引入了HandlerMethod 表示一个@RequestMapping方法的抽象.这种抽象 新的支持类在整个过程中将其用作处理程序实例. 例如,HandlerInterceptor可以将处理程序从Object强制转换为 HandlerMethod并获得访问目标控制器的方法,其 注释等
A second notable difference is the introduction of a HandlerMethod abstraction to represent an @RequestMapping method. This abstraction is used throughout by the new support classes as the handler instance. For example a HandlerInterceptor can cast the handler from Object to HandlerMethod and get access to the target controller method, its annotations, etc.
默认情况下,新类由MVC命名空间和 通过@EnableWebMvc基于Java的配置.现有的课程将 继续可用,但建议使用新类 向前.
The new classes are enabled by default by the MVC namespace and by Java-based configuration via @EnableWebMvc. The existing classes will continue to be available but use of the new classes is recommended going forward.
这篇关于在dispatcher.xml中不建议使用DefaultAnnotationHandlerMapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!