Java 为org.springframework.beans.propertyeditors.StringTrimmerEditor实例化bean时出错
下面是我的applicationContext.xml的外观:Java 为org.springframework.beans.propertyeditors.StringTrimmerEditor实例化bean时出错,java,spring,Java,Spring,下面是我的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.
<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>
。。。。。
<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>
<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>
我得到这个错误:
<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:错误
正在创建中定义了名为“CustomEditorConfigure”的bean
ServletContext资源[/WEB-INF/spring servlet.xml]:初始化
豆荚失败;嵌套异常是
org.springframework.beans.typemischException:转换失败
将“java.util.LinkedHashMap”类型的属性值转换为所需类型
属性“CustomEditor”的“java.util.Map”;嵌套异常是
java.lang.IllegalArgumentException:无法转换类型的值
[org.springframework.beans.propertyeditors.StringTrimmerEditor]到
属性的必需类型[java.lang.Class]
“CustomEditor[java.lang.String]”:PropertyEditor
返回[org.springframework.beans.propertyeditors.ClassEditor]
类型值不正确
[org.springframework.beans.propertyeditors.StringTrimmerEditor]
<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>
缔约国强调如下:
<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>
指定要通过映射注册的自定义编辑器,使用所需类型的类名作为键,使用关联PropertyEditor的类名作为值
<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>
因此,您传入类名,而不是bean本身,作为映射中每个条目的值
<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>
试着替换
<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>
<entry key="java.lang.String">
<ref bean="stringTrimmerEditor"/>
</entry>
与
<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>
与
<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:创建名为“org.springframework.context.annotation.InternalAutowiredNotationProcessor”的bean时出错:bean的实例化失败;嵌套异常为org.springframework.beans.beans实例化异常:无法实例化bean类[org.springframework.beans.propertyeditors.StringTrimmerEditor]:未找到默认构造函数;嵌套异常是java.lang.NoSuchMethodException:org.springframework.beans.propertyeditors.StringTrimmerEditor。@Chandan:很抱歉,我以前的建议不起作用。我编辑我的答案是为了提出另一个建议——这对你有用吗?@Chandan:我再次编辑我的答案是为了提出一些有效的建议——我已经测试过了。抱歉没有测试我以前的建议。