Spring 3 @NumberFormat not working with form:input Tag

≯℡__Kan透↙ 提交于 2019-12-06 09:51:40

ConversionServiceFactoryBean does not registers default formatters.

You need to use FormattingConversionServiceFactoryBean
So do as below

<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="com.my.StringToDoubleConverter" />
        </list>
    </property>
</bean>



if you want to use only NumberFormatAnnotationFormatterFactory which does the Number Formatting (processes @NumberFormat Annotation ) and disable its other default formatters then do as below

<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    <property name="registerDefaultFormatters" value="false" />
    <property name="formatters">
    <set>
        <bean class="org.springframework.format.number.NumberFormatAnnotationFormatterFactory" />
    </set>
    </property>
     <property name="converters">
    <list>
        <bean class="com.my.StringToDoubleConverter" />
    </list>
</property>
</bean>

Source:Spring Docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!