DefaultAnnotationHandlerMapping is deprecated in dispatcher.xml

◇◆丶佛笑我妖孽 提交于 2019-12-24 10:42:49

问题


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 ?

code as such the following

<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 and AnnotationMethodHandlerAdapter is strikethrough


回答1:


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 introduces a new set of support classes for processing requests with annotated controllers:

RequestMappingHandlerMapping

RequestMappingHandlerAdapter

ExceptionHandlerExceptionResolver

These classes are a replacement for the existing:

DefaultAnnotationHandlerMapping

AnnotationMethodHandlerAdapter

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.

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.

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.



来源:https://stackoverflow.com/questions/31902767/defaultannotationhandlermapping-is-deprecated-in-dispatcher-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!