将不可序列化的属性值设置为 HttpSession



部署项目时有时会出错,但不是每次都出错。本地豆在错误时不起作用

错误信息

Warning:   JSF1063: WARNING! Setting non-serializable attribute value into HttpSession (key: localBean, value class: LocalBean).

本地豆

package com.mycompany.crm;
import java.io.Serializable;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
@ManagedBean
@SessionScoped
public class LocalBean implements Serializable{
    public Locale locale;
    @PostConstruct
    public void init() {
        locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    }
    public Locale getLocale() {
        return locale;
    }
    public String getLanguage() {
        return locale.getLanguage();
    }
    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
    }
}

尝试在类中放置一个serialVersionUID字段,如下所示:

private static final long serialVersionUID = -1;

相关内容

  • 没有找到相关文章

最新更新