如何将自定义版本的WebDataBinder注入Spring 3 MVC?

如何将自定义版本的WebDataBinder注入Spring 3 MVC?,第1张

如何将自定义版本的WebDataBinder注入Spring 3 MVC?

这不是一个简单的任务。Spring允许进行大量的自定义,但是,该死,这种更改并不有趣。

您需要扩展

RequestMappingHandlerAdapter
该类并重写以下方法

protected InitBinderDataBinderFactory createDataBinderFactory(List<InvocableHandlerMethod> binderMethods)        throws Exception {    return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer());}

除了返回

ServletRequestDataBinderFactory
,您需要返回一个
InitBinderDataBinderFactory
返回自定义
WebDataBinder
实例的自定义。

此更改意味着您不能使用默认设置

@EnableWebMvc
<mvc:annotation-driven/>
配置。那是因为它们
RequestMappingHandlerAdapter
默认使用,但是您需要注册自己的类。

但是,您可以覆盖带

@Bean
注释的
WebMvcConfigurationSupport#requestMappingHandlerAdapter()
方法,并提供自己的实现以返回自己的类型。查看该实现对提示的作用。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5123281.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-17
下一篇2022-11-17

发表评论

登录后才能评论

评论列表(0条)

    保存