<-! SysManageImpl ->
<-! SysManagerAction ->
But when I call the method instance sysManage used SysManageImpl Action class , throws a null pointer exception , I did all kinds of tests , show is sysManage no instance of , I asked the teacher, the teacher said it might be Struts2 and Spring integration process has gone wrong , I want to ask Struts2 and Spring integration process what issues need attention , there is no instance of sysManage what is the reason ?
//Action类
public class SysManagerAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private HttpServletRequest request;
private Student student;
private SysManageImpl sysManager;
//省略各setter和getter方法
public String add(){
try{
sysManager.sysUpdateStudent(student, operateType);
return "addSuccess";
}catch (Exception e) {
e.printStackTrace();
return "addFail";
}
}
}
------ Solution ------------------------------------ --------
action in providing access to the object you want get and set methods , do not understand why you have to be omitted.
add that sentence is to get inside without a sysManager instance of an object , I think it is not because there is access to an instance of an object , which is automatically paid to the member variables of this class sysManager, it would not be a null pointer a .
I am also a novice, under mutual exchange .
------ Solution ---------------------------------------- ----
bean name="/sysManagerAction"
here is not more than a " / " And you have to pay attention to the Action attribute to inject setter
------ For reference only ---------- -----------------------------
If I add the following two statements in the add method can be performed properly, do not throw a null pointer exception
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
sysManager = (SysManageImpl)ctx.getBean("sysManage");
so more is definitely not complete instantiation , in the end is why, freshman big knees and begged God enlighten.
------ For reference only -------------------------------------- -
I did not omit , but here a little too much to write .... avoid code , we see tired.
------ For reference only ---------------------------------- -----
solved !
indeed Struts2 and Spring integration process out of the question .
In Struts.xml the action configuration , class configured in applicationContext.xml Action should write the bean class id.
The original wording :
After integrating the correct wording :
sysManagerAction which is the bean id.
------ For reference only -------------------------------------- -
well, I resolved, you look at the 4th floor bar.
------ For reference only -------------------------------------- -
If no bean with name id , then use / can.
problem has been resolved out , is struts.xml in the class action should applicationContext.xml the bean 's name or id
------ For reference only ------- --------------------------------
thank landlord solutions. . Scrapped three days. . Blame themselves did not understand the configuration of the three frameworks. .
没有评论:
发表评论