The object of the dao layer cannot be obtained

There was a problem when I was working on a project recently. The null pointer exception that everyone is very familiar with. To be honest, I haven't encountered this exception for a long time. , tangled all night. . .

 

The framework used is springmvc

 

The business at that time was probably like this. It needed a timed task to poll and query, and send emails according to the results, all through annotations. The timed task also obtained the object of the dao layer through annotations, but the query in the timed task is empty. The pointer is abnormal, but it is no problem to put the query code in the service layer. The final solution is as follows:

 

[java] view plain copy
 
print ?
  1. IAlarmDao alarmDao = (IAlarmDao) BeanFactoryUtil.getBean("alarmDao");  
IAlarmDao alarmDao = (IAlarmDao) BeanFactoryUtil.getBean("alarmDao");

 

 

You don't need to use annotations to get objects, you can directly use the factory class, so that you can get the object of the dao layer and call the query method without any problem.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326328069&siteId=291194637