这是EJB还是ManagedBean?要成为EJB bean,必须由@stateful,@ stateless或@Singleton注释吗?我认为@SessionScoped和@ApplicationScoped类也是EJB bean。这是对的吗?
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
@Named("userData")
@SessionScoped
public class UserData implements Serializable {
private static final long serialVersionUID = 1L;
public UrlData data;
public UrlData getData() {
return data;
}
public void setData(UrlData data) {
this.data = data;
}
}
答案 0 :(得分:1)
@SessionScoped和@ApplicationScoped是ManagedBean而不是EJB的一部分,它将类作为JavaServer Faces的资源。
这是将EJB注入ManagedBean的示例代码
@ManagedBean
@SessionScoped
public class Count {
@EJB
private CounterBean counterBean;
private int hitCount;
public Count() {
this.hitCount = 0;
}
public int getHitCount() {
hitCount = counterBean.getHits();
return hitCount;
}
public void setHitCount(int newHits) {
this.hitCount = newHits;
}
}