当前位置: 首页 > 知识库问答 >
问题:

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

贲文景
2023-03-14

下面是我的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>

我得到了这个错误:

创建异常:创建名称为“自定义编辑器配置器”的 Bean 时出错:在 Servlet上下文资源 [/WEB-INF/Spring-servlet.xml]中定义名称的 Bean 时出错: 初始化 Bean 失败;嵌套的异常是组织.Spring框架.豆.类型不匹配异常: 无法将类型为 “java.util.LinkedHashMap' 的属性值转换为属性 ”自定义编辑器“ 所需的类型 ”java.util.Map“;嵌套的异常是 java.lang.非法描述异常:无法将类型 [org.springframework.beans.属性编辑器.字符串编辑器] 的值转换为属性“自定义编辑器”的必需类型 [java.lang.类]:属性编辑器 [组织.springframework.beans.propertyeditors.类] 返回了不适当的类型值 [组织.Spring框架工作.beans.beans.属性编辑器.字符串编辑器]

共有1个答案

邵阳德
2023-03-14

自定义编辑器配置器类的 set自定义编辑器方法的文档声明如下(强调我的):

指定要通过Map注册的自定义编辑器,将所需类型的类名用作键,将关联PropertyEditor的类名作为值

因此,您将类名(而不是 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>
 类似资料:
  • 我是micronnaut的新手,我正在尝试包括以下内容来运行本机查询,应用程序运行正常,但是我所有带有@MincronautTest注释的功能测试都失败了,并显示以下消息 消息:给定限定符@Named('default')不存在[org.hibernate.SessionFactory]类型的bean。确保bean未被bean需求禁用(启用“io.micronaut.context.conditi

  • 7.3.2 bean的实例化 bean的定义本质上是创建一个或多个对象的配方。当被请求时,容器在配方中查找指定名称的bean,使用bean定义中封装的配置元数据来创建(或得到)一个实际的对象。 如果使用基于XML的配置元数据,在<bean/>元素的class属性中指定被实例化对象的类型(或类)。class属性通常是强制性的,它在内部实质是BeanDefinition实例的Class属性。(例外情况

  • 我正试图启动chrome浏览器使用远程WebDriver与以下代码。 我得到了以下错误: 线程“main”中的异常org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败。 我检查了端口9898是否打开。我在中的主机中添加了localhost 更新:我可以看到另外两个例外。

  • 当我尝试使用循环类的Application Context创建bean时,我面临以下错误!Circle类实现了接口,其中包含一个方法。 配置: 我正在学习Spring,并在eclipse中设置了一个Java项目,其中包含所有必需的jar(Spring和Apache公共日志记录)。我在src文件夹的类路径中有spring.xml。我也尝试过下载最新的jar(Spring 4.0.4版本,以前适用于4

  • 这是我的index.html 和我的servlet类 <代码>包学生;@WebServlet(“/StudentSurveyFormSubmit”)公共类StudentSurveyFormSubmit扩展HttpServlet{protected void doGet(HttpServletRequest request,HttpServletResponse response)throws Se