@SessionScoped 无法解析为类型

@SessionScoped cannot be resolved to a type

我在我的托管 bean 中使用 @SessionScoped,它给我错误。

@SessionScoped cannot be resolved to a type

我错过了什么?

相关代码:

package javaeetutorial.guessnumber;

import java.io.Serializable;
import java.util.Random;

@Named
@SessionScoped
public class UserNumberBean implements Serializable {
    // Do stuff.
}

添加下面的导入,

import javax.enterprise.context.RequestScoped;

以后你可以一直用你IDE为你解决进口问题,在eclipse中ctrl+shift+o。

希望对您有所帮助。

改为添加面孔库:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;