ssh 注入了bean 但是取值为null
application.xml中的部分配置:<!--配置HibernateTemplate--><beanid="hibernateTemplate"class="org...
application.xml中的部分配置:
<!--配置 Hibernate Template -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置student的相关业务bean -->
<bean id="StuDAO" class="com.haitu.dao.StuDAO">
<property name="hibernateTemplate">
<ref local="hibernateTemplate" />
</property>
</bean>
<bean id="StuService" class="com.haitu.service.StuService" >
<property name="StuDAO">
<ref bean="StuDAO"></ref>
</property>
struts中的配置:
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="student" extends="struts-default">
<action name="addStudent" class="com.haitu.action.StudentAction" method="addStudent">
<result name="success">index.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
public class StudentAction extends ActionSupport {
private Stu stu;
private StuService service;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
action中的配置:
public String addStudent()
{
System.out.println("this is service11111.................."+this.service);
boolean res=service.addStudent(stu);
if(res)
{
return ActionSupport.SUCCESS;
}else
return ActionSupport.ERROR;
}
public Stu getStu() {
return stu;
}
public void setStu(Stu stu) {
this.stu = stu;
}
public StuService getService() {
return service;
}
public void setStuService(StuService service) {
this.service = service;
System.out.println("this is service.................."+service);
}
}
</bean>
<bean id="StudentAction" class="com.haitu.action.StudentAction">
<property name="StuService" >
<ref bean="StuService" ></ref>
</property>
</bean>
启动服务器是后台输出:this is service..................com.haitu.model.StuService@1d978ea
执行addStudent方法时this is service11111..................null
service为空,导致空指针异常。 展开
<!--配置 Hibernate Template -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置student的相关业务bean -->
<bean id="StuDAO" class="com.haitu.dao.StuDAO">
<property name="hibernateTemplate">
<ref local="hibernateTemplate" />
</property>
</bean>
<bean id="StuService" class="com.haitu.service.StuService" >
<property name="StuDAO">
<ref bean="StuDAO"></ref>
</property>
struts中的配置:
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<package name="student" extends="struts-default">
<action name="addStudent" class="com.haitu.action.StudentAction" method="addStudent">
<result name="success">index.jsp</result>
<result name="error">error.jsp</result>
</action>
</package>
</struts>
public class StudentAction extends ActionSupport {
private Stu stu;
private StuService service;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
action中的配置:
public String addStudent()
{
System.out.println("this is service11111.................."+this.service);
boolean res=service.addStudent(stu);
if(res)
{
return ActionSupport.SUCCESS;
}else
return ActionSupport.ERROR;
}
public Stu getStu() {
return stu;
}
public void setStu(Stu stu) {
this.stu = stu;
}
public StuService getService() {
return service;
}
public void setStuService(StuService service) {
this.service = service;
System.out.println("this is service.................."+service);
}
}
</bean>
<bean id="StudentAction" class="com.haitu.action.StudentAction">
<property name="StuService" >
<ref bean="StuService" ></ref>
</property>
</bean>
启动服务器是后台输出:this is service..................com.haitu.model.StuService@1d978ea
执行addStudent方法时this is service11111..................null
service为空,导致空指针异常。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询