Why does blackInfoDao.selectBlackByCjid report null pointer?


@Controller(value = "blackServiceAction")
@Scope("prototype")
public class BlackServiceAction extends ActionSupport {

    private static final long serialVersionUID = -5155883818336614584L;

    private BlackInfoDaoImpl blackInfoDao;


    public String execute() throws ServletException, IOException {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        

        try {
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            String customerId = request.getParameter("customerId");
            String address = request.getParameter("address");
            String result = isBlack(customerId,address);
            response.getWriter().print(result);
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;

    }

    //
    public String isBlack(String customerId,String address) {
        
        if(customerId==null||customerId.equals("")){
            return "2";
        }
        try {
            List<BlackInfo> list = blackInfoDao.selectBlackByCjid(customerId,address);
            String isblack = null;
            if(list.size()>0){
                isblack = "1";
                return isblack;
            }
            return "0";
        } catch (Exception e) {
            System.out.println(e);
            return "2";
        }
    }

}
2018-09-03 19:52:58,743 INFO [http-7001-Processor23]    Detected AnnotationActionValidatorManager, initializing it...
java.lang.NullPointerException
May.22,2021

private BlackInfoDaoImpl blackInfoDao; is not initialized,

add the @ Autowired annotation, dependency injection for spring.

@Autowired
private BlackInfoDaoImpl blackInfoDao;

because your blackInfoDao is not initialized.
two solutions:

  1. initialize blackInfoDao.
private BlackInfoDaoImpl blackInfoDao = new BlackInfoDaoImpl();
  1. automatically inject this class
@Autowired
private BlackInfoDaoImpl blackInfoDao;
Menu