1
votes

Here how my applicationContext.xml looks like:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:sec="http://www.springframework.org/schema/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">

..... .....

<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
   <property name="customEditors">
        <map>
           <entry key="java.lang.String">
                <ref bean="stringTrimmerEditor"/>
            </entry>
        </map>
    </property>
 </bean>

I am getting this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customEditorConfigurer' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.LinkedHashMap' to required type 'java.util.Map' for property 'customEditors'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [org.springframework.beans.propertyeditors.StringTrimmerEditor] to required type [java.lang.Class] for property 'customEditors[java.lang.String]': PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value of type [org.springframework.beans.propertyeditors.StringTrimmerEditor]

1

1 Answers

0
votes

The documentation for the setCustomEditors method of the CustomEditorConfigurer class states the following (emphasis mine):

Specify the custom editors to register via a Map, using the class name of the required type as the key and the class name of the associated PropertyEditor as value

So you pass in the class name, not the bean itself, as the value in each entry in the map.

Try replacing

<entry key="java.lang.String">
    <ref bean="stringTrimmerEditor"/>
</entry>

with

<entry key="java.lang.String"
       value="org.springframework.beans.propertyeditors.StringTrimmerEditor" />

with

<entry key="java.lang.String">
    <bean class="org.springframework.beans.propertyeditors.StringTrimmerEditor">
        <!-- change the value as necessary.  --> 
        <constructor-arg name="emptyAsNull" value="false" />  
    </bean>
</entry>