我用的框架是spring+ibatis+struts1
我的action调用service的时候提示空指针异常,我怀疑是没有注入的问题,但找了半天没有找出错误.希望各位高手帮帮小弟!
action Class codeprivate ITestService testService;
public ITestService getTestService() {
return testService;
}
public void setTestService(ITestService testService) {
this.testService = testService;
}......public ActionForward getUserList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
List testList = testService.doselectall();//这里报错 空指针异常
request.setAttribute("testList", testList);
return mapping.findForward("list");
}service class codeprivate ITestDao testDao;
public ITestDao getTestDao() {
return testDao;
} public void setTestDao(ITestDao testDao) {
testDao = testDao;
}...... public List doselectall() {
return testDao.doselectall();
}spring.xml code <bean id="testDao" class="com.dne.a.persistence.TestDao">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<bean id="testService" parent="baseTransactionProxyforIbatis">
<property name="target">
<bean class="com.dne.a.service.TestService">
<property name="testDao" ref="testDao" />
</bean>
</property>
</bean>一早上看的头都晕了,也没发现哪里错了,很纠结啊!

解决方案 »

  1.   

    怎么没有配置action 代码呢?
      

  2.   

    你只是把dao注入到service,并加了事务,并没有把service注入到action中
      

  3.   

    Action 没有注入到spring配置文件中
     
    这样你的spring和struts 并没有关联起来
      

  4.   

    既然使用了Spring,直接使用Spring的MVC好了,非常简单,性能还不错,不用再使用Struts了
      

  5.   

    我是个才入行的新人,问题解决了,是项目经理帮我弄的,这是项目的原型模板是公司的一个商业项目,经理拿我做的,楼上说的改其他的可能不现实,不过还是谢谢各位,经理弄了半天好像说我的service里个getset有问题,我也纳闷,我看来看去没什么问题啊,他重写一遍后,打个断点运行一看testdao就不是NULL了有值了  我很费解!你们知道为什么吗?
      

  6.   

    具体是怎么样的呢?我的action里也有service的get,set方法这不是注入吗?
    别生气我新手可能很多搞混淆或则搞不明白,你能简单的解释下吗?
      

  7.   

    spring。xml中的action我也配置了,可能我下午我忙昏了,忘贴出来<bean name="/Test_list"
    class="com.dne.a.action.TestAction">
    <property name="testService" ref="TestService" />
    </bean>
      

  8.   


        private ITestDao testDao;
     ......
        public List doselectall() {
            return testDao.doselectall();
        }这个方法,挺好玩的
      

  9.   

    一个是service的 一个是dao的   我命名不是很规范,我错
      

  10.   

    你只是把dao注入到service,并加了事务,并没有把service注入到action中
      

  11.   

    这样都不行的话,你贴一下struts的配置文件吧..也许你没有把struts交给spring管理