标签:
Mina 配置中的 CustomEditorConfigurer
太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商业用途-保持一致”创作公用协议
<!--此部分被 NioSocketAcceptor 隐式使用,无此则会报字符串无法转换成 InetSocketAddress --> <bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="java.net.SocketAddress" value="org.apache.mina.integration.beans.InetSocketAddressEditor" /> </map> </property> </bean>
可以想到,从字符串到 SocketAddress 的转换,会偿试使用该自定义属性编辑器。
具体属性编辑器的用法,还需进一步研究,暂时只知道由它转换即可。
经查 Spring 官方文档,获得如下 CustomEditorConfigurer 的类说明:
public class CustomEditorConfigurer extends Object implements BeanFactoryPostProcessor, Ordered
BeanFactoryPostProcessor
接口的实现,它允许方便地注册自定义的 属性编辑器 。
BeanFactoryPostProcessor
implementation that allows for convenient registration of custom property editors
.In case you want to register PropertyEditor
instances, the recommended usage as of Spring 2.0 is to use custom PropertyEditorRegistrar
implementations that in turn register any desired editor instances on a given registry
. Each PropertyEditorRegistrar can register any number of custom editors.
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="propertyEditorRegistrars"> <list> <bean class="mypackage.MyCustomDateEditorRegistrar"/> <bean class="mypackage.MyObjectEditorRegistrar"/> </list> </property> </bean>
最好通过属性 customEditors
注册 PropertyEditor
类。Spring 会为每一次编辑意向创建全新的该类的实例:
It‘s perfectly fine to register PropertyEditor
classes via the customEditors
property. Spring will create fresh instances of them for each editing attempt then:
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="java.util.Date" value="mypackage.MyCustomDateEditor"/> <entry key="mypackage.MyObject" value="mypackage.MyObjectEditor"/> </map> </property> </bean>
注意,以下情况不能使用属性来注册属性编辑器:
Note, that you shouldn‘t register PropertyEditor
bean instances via the customEditors
property as PropertyEditor
s are stateful and the instances will then have to be synchronized for every editing attempt. In case you need control over the instantiation process of PropertyEditor
s, use aPropertyEditorRegistrar
to register them.
Also supports "java.lang.String[]"-style array class names and primitive class names (e.g. "boolean"). Delegates to ClassUtils
for actual class name resolution.
NOTE: Custom property editors registered with this configurer do not apply to data binding. Custom editors for data binding need to be registered on the DataBinder
: Use a common base class or delegate to common PropertyEditorRegistrar implementations to reuse editor registration there.
PropertyEditor
, PropertyEditorRegistrar
, ConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar)
, ConfigurableBeanFactory.registerCustomEditor(java.lang.Class<?>, java.lang.Class<? extends java.beans.PropertyEditor>)
,DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
Mina 配置中的 CustomEditorConfigurer
标签:
原文地址:http://blog.csdn.net/opengl_es/article/details/42453923