Home > Back-end >  JPA Resource for Java. Lang. NullPointerException: null
JPA Resource for Java. Lang. NullPointerException: null

Time:10-01

Jpa under the controller can be used but the custom class methods can not have been submitted to the empty why

The controller jpa code normal
 

//controller class already annotation Resource method
@ RequestMapping ("/reg ")
Public String reg (it request, HttpServletResponse response, @ Valid the UserInfo backstageUser, BindingResult BindingResult) {

The UserInfo user=userDao. GetOne (1);
System. The out. Println (" system111: "+ user. GetName ());//here can normal to get the data


CommonUtil111 aa=new CommonUtil111 ();
Aa. Aa (request);//call the method will be an error
}


CommonUtil111
 
Public class CommonUtil111 {
@ the Resource
Public UserDao UserDao;

Public String aa (it request) {
The UserInfo w=userDao. GetOne (1);//there can not have been submitted to the Java lang. NullPointerException: null
System. The out. Println (" system444: "+ w.g etName ());
Return "";
}
}




UserDao
 

Public interface UserDao extends JpaRepository {

}

CodePudding user response:

What a great god help me see otherwise good trouble ah

CodePudding user response:

Use the @autowired UserDao UserDao

CodePudding user response:

Null fault is still the same

CodePudding user response:

Know how to solve
  • Related