NullPointerException while trying to access @EJB bean in managed bean constructor
问题 I've an EJB service. @Stateless public class SomeService {} I'd like to inject this in a viewscoped bean and initialize with it: @ManagedBean @ViewScoped public class ViewBean implements Serializable { @EJB private SomeService someService; public ViewBean() { System.out.println(someService.getEntity()); } } However, it throws the following exception: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.example.ViewBean. at com.sun.faces.mgbean.BeanBuilder