Spring的弃用警告

6

在应用程序启动时,我收到以下警告信息(数十次):

Dec 08, 2012 5:10:41 PM org.springframework.beans.TypeConverterDelegate findDefaultEditor
WARNING: PropertyEditor [sun.beans.editors.EnumEditor] found through deprecated global PropertyEditorManager fallback - consider using a more isolated form of registration, e.g. on the BeanWrapper/BeanFactory!

谷歌显示这是非常常见的信息,但不幸的是没有显示为什么会发生。我该如何避免这些警告?

Spring版本为2.5.6。

2个回答

8

添加自定义编辑器固定警告:

public final class EnumPropertyEditor extends PropertyEditorSupport {

    public EnumPropertyEditor() {
    }

    @Override
    public String getAsText() {
       return (String) getValue();
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
       setValue(text);
   }
}

在配置文件中:

<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
    <property name="customEditors">
        <map>
            <entry key="java.lang.Enum">
                <bean class="package.EnumPropertyEditor">
                </bean>
            </entry>
        </map>
    </property>
</bean>

3
它告诉您正在使用已弃用的回退方法来查找枚举属性编辑器,而不是使用在Spring中注册的属性编辑器,并且您应该考虑使用专用的枚举属性编辑器并将其注册到Spring中,使用文档中描述的机制。

如果不这样做,在将来的Spring版本中,您的代码可能无法正常工作,因为Spring将无法再使用此后备机制。

话虽如此,3.1.x版本仍具有此后备机制。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接