user3189384
user3189384

Reputation: 53

In spring4 the CustomEditorConfigurer throws error while i am setting custom editor property

Using org.springframework.beans.factory.config.CustomEditorConfigurer when I am trying to map a custom editor to java.util.Locale it throws an exception:

Cannot convert value of type [org.test.beans.LocalePropertyEditor] to required type [java.lang.Class] for property 'customEditors[java.util.Locale]'

 PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value of type [org.test.beans.LocalePropertyEditor]
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:263)
        at org.springframework.beans.TypeConverterDelegate.convertToTypedMap(TypeConverterDelegate.java:623)
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:208)
        at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:458)

I have LocalePropertyEditor class to convert --String value for valid Java TimeZone id ,is converted to a TimeZone object.

public class LocalePropertyEditor extends PropertyEditorSupport {

public void setAsText(String text) {

    }

}

I am setting it using following entry

<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Locale"><bean class="org.test.beans.LocalePropertyEditor" /></entry>
</map>
</property>
</bean>

Upvotes: 1

Views: 1864

Answers (1)

user3189384
user3189384

Reputation: 53

we need to use

<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Locale" value="org.test.beans.LocalePropertyEditor"/>
</map>
</property>
</bean>

The Spring will take care itself the instantiation of bean.

Upvotes: 2

Related Questions