Вот как выглядит мой applicationContext.xml:
<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>
Я получаю эту ошибку:
org.springframework.beans.factory.BeanCreationException: Ошибка создания компонента с именем "customEditorConfigurer", определенным в ресурсе ServletContext [/WEB-INF/spring-servlet.xml]: Инициализация компонента не выполнена; Вложенное исключение - org.springframework.beans.TypeMismatchException: Не удалось преобразовать значение свойства типа "java.util.LinkedHashMap" в требуемый тип "java.util.Map" для свойства "customEditors"; nested exception is java.lang.IllegalArgumentException: Невозможно преобразовать значение типа [org.springframework.beans.propertyeditors.StringTrimmerEditor] в требуемый тип [java.lang.Class] для свойства "customEditors [java.lang.String]": PropertyEditor [ org.springframework.beans.propertyeditors.ClassEditor] возвращает недопустимое значение типа [org.springframework.beans.propertyeditors.StringTrimmerEditor]
Документация setCustomEditors
метод класса CustomEditorConfigurer состояний следующее (курсив мой):
Укажите настраиваемые редакторы для регистрации через карту, используя имя класса требуемого типа в качестве ключа и имя класса связанного с ним PropertyEditor в качестве значения
Таким образом, вы передаете имя класса, а не сам компонент, как значение в каждой записи на карте.
Попробуйте заменить
<entry key="java.lang.String">
<ref bean="stringTrimmerEditor"/>
</entry>
с
<entry key="java.lang.String"
value="org.springframework.beans.propertyeditors.StringTrimmerEditor" />
с
<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>