NullPointerException Problem solving when "original" integrates spring4+hibernate4+struts2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.