1. Opening remarks
I believe that the SSH beginner must have encountered this problem, but it is not the solution, understood after the epiphany.
2, problem description
The program implementation process is called UserService in Useraction , and theDAO class is called in the UserService implementation class . a nullpointerexception error occurred during the operation of the program in the console:
The invocationtargetexception function is entered during debugging:
3. Solution
Debug found that the userservice code was having problems invoking DAO:
debugging found that the parameters are normal, but in 59 lines of code error, and can not directly enter the Basedao get method. Enter the following invocationtargetexception code:
After debugging, the console output java.lang.NullPointerException error.
Think of invoking the Invoke () method when executing the Get method of the Basedao object.
method Invoke () methods source code:
The code sees that the NullPointerException () error is returned when the passed in object is empty. So it is certain that the DAO object passed in is empty.
Take a look at spring's management of each object, check the code to see where the problem is, andDAO is not injected.
Knowing the problem, the solution:
Add a DAO object to the spring IOC container
In 16 lines plus @Resource(name = "Basedao") annotation , tell Spring to let Spring inject the created Basedao object into UserService.
So spring Nullpointerexception,invocationtargetexception's problem is solved.
NullPointerException Problem solving when "original" integrates spring4+hibernate4+struts2