Accessing injected dependency in managed bean constructor causes NullPointerException
问题 I\'m trying to inject a DAO as a managed property. public class UserInfoBean { private User user; @ManagedProperty(\"#{userDAO}\") private UserDAO dao; public UserInfoBean() { this.user = dao.getUserByEmail(\"test@gmail.com\"); } // Getters and setters. } The DAO object is injected after the bean is created, but it is null in the constructor and therefore causing NullPointerException . How can I initialize the managed bean using the injected managed property? 回答1: Injection can only take