Registering PropertyEditors with the Spring container

This article is taken from Getting started with Spring Framework book


To register property editors with the Spring container, you need to do the following:
1. Create a class that implements Spring’s PropertyEditorRegistrar interface. This class is responsible for registering property editors with the Spring container.
2. Configure the PropertyEditorRegistrar implementation as a Spring bean in the application context XML file.
3. Configure Spring’s CustomEditorConfigurer special bean in the application context XML file, and provide it with reference to the PropertyEditorRegistrar implementation (that you created in step 1 and configured in step 2).


The following configuration shows how CustomEditorConfigurer is configured:

<bean id=" myPropertyEditorRegistrar" class="sample.spring.chapter02.beans.MyPropertyEditorRegistrar " />

<bean id="editorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
         <property name="propertyEditorRegistrars">
            <list>
                 <ref bean="myPropertyEditorRegistrar"/>
            </list>
         </property>
</bean>

For an example, refer to ch02-simple-types-examples project. 

Comments

Popular posts from this blog

Getting started with Spring Framework, Second Edition now available