gpt4 book ai didi

java - 实例化 org.springframework.beans.propertyeditors.StringTrimmerEditor 的 bean 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 14:55:33 26 4
gpt4 key购买 nike

这是我的 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: 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]

最佳答案

documentation for the setCustomEditors method of the CustomEditorConfigurer class声明如下(强调我的):

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

因此,您传入类名,而不是 bean 本身,作为映射中每个条目的值。

尝试更换

<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>

关于java - 实例化 org.springframework.beans.propertyeditors.StringTrimmerEditor 的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23252698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com