Why does my FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal() code runs to NullPointer?
问题 I have a stateless bean which has a method, where I want to get the current/logged user. My code to get it: Principal p1 = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); But I am getting nullpointer exception on this. Why is that? Or is there any other way to get the logged user? I am using weblogic. 回答1: You're not supposed to grab the FacesContext in an EJB. Even more, your EJBs should be completely free from any JSF dependencies. In other words, you should not