当我运行此代码时,我会出现此错误
范围类型javax.enterprise.context.RequestScoped没有活动的上下文
任何帮助请,我该怎么办? 我正在使用此代码在不同用户之间进行聊天,因此我是servlet bean提取不同的连接用户
import javax.enterprise.context.RequestScoped;
@RequestScoped
@Named
public class ServletBean implements Serializable{
private static final long serialVersionUID = 1L;
/**
*
*/
@Inject
CompanyController companyController;
@Inject
CandidateController candidateController;
private int id;
private int idCandidate;
@PostConstruct
public void display(){
ELContext elContext = FacesContext.getCurrentInstance()
.getELContext();
companyController = (CompanyController) FacesContext
.getCurrentInstance().getApplication().getELResolver()
.getValue(elContext, null, "companyController");
ELContext elContext1 = FacesContext.getCurrentInstance()
.getELContext();
candidateController = (CandidateController) FacesContext
.getCurrentInstance().getApplication().getELResolver()
.getValue(elContext1, null, "candidateController");
if (companyController.getIdCompany()!= 0) {
id=companyController.getIdCompany();
}
if (candidateController.getConnectedCandidate().getIdUserInformation()!=0) {
id = candidateController.getConnectedCandidate().getIdUserInformation();
}
System.out.println("ligne 11+id1"+id+idCandidate);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getIdCandidate() {
return idCandidate;
}
public void setIdCandidate(int idCandidate) {
this.idCandidate = idCandidate;
}
}
@ServerEndpoint(value = "/websocket/{client-id}")
public class MyServerEndpoint {
private static final LinkedList<Session> clients = new LinkedList<Session>();
@Inject
ServletBean servletBean;
@Inject
ChatlogBean chatlogBean;
ChatLog chatLog;
@OnOpen
public void onOpen(Session session) {
System.out.println("ligne 26"+ session.getUserPrincipal()+"*******"+session.getId());
clients.add(session);
}
@OnMessage
public void onMessage(String message,
@PathParam("client-id") String clientId) {
for (Session client : clients) {
try {
client.getBasicRemote().sendObject(clientId + ": " + message);
System.out.println("ligne 26 message" + message + "clientId"
+ clientId);
System.out.println("ligne 57"+servletBean.getId());
} catch (IOException e) {
e.printStackTrace();
} catch (EncodeException e) {
e.printStackTrace();
}
}
}
@OnClose
public void onClose(Session peer) {
clients.remove(peer);
}
}