注册类型转换器时需要注意的细节
在告知spring框架,我创建的 mydateconverter 是一个类型转换器时,我的id是这样的(用了大写),但是此处必须要注意的是 这里的ID不是自定义的,必须是 conversionService ,否则会报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'person' defined in class path resource [applicationContext1.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date' for property 'date': no matching editors or conversion strategy found将原代码改成
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<set>
<ref bean="mydateconverter"/>
</set>
</property>
</bean>
重点是要用小写