Action里面有iService的setter方法吗?

解决方案 »

  1.   

    action里面应有iService的getter和setter方法
      

  2.   

    你的代码贴的不全!我初步判断,应该问题出在以下几个地方,你可以参考一下:第一,<bean id="serviceAction" class="cn.test.action.ServiceAction" singleton="false">
    <property name="iService">
    <ref bean = "iService"/>
    </property>
    </bean> 
    这里的id属性要与struts.xml中的action的name属性一致;第二,你的Spring的事务管理模板好象形同虚设啊?正常它应该注入给服务类接口的,你的配置文件里只配置了服务类的实现类,没有服务类接口啊?难道你没有使用接口?如果你有接口,应该还有下面这个配置:<!--  Services  -->
          <bean  id ="iService" extends="继承一个抽象事务模板">           
             <property  name ="target" >
                 <ref  bean ="指向实现类的bean的name属性" />
             </property >
         </bean >  
    然后把这个bean注入给Action。第三,检查你的Action类,看看IService的对象iService是不是不小心写成这样的:IService iService=new IServiceImpl();这是新手接触Spring非常容易犯的错误,其原因是对IOC还没有很好的理解!
      

  3.   

    我没用过struts2.0,不过据说是从webwork迁移过来的。我对webwork有一点了解,如果从webwork的观点来看,好像ApplicationContext.xml里面不需要对Action进行配置,这是其一。其二,使用spring通过setter注入,在某些时候,setter的写法有一点特殊,和用eclipse自动完成的setter不同:比如iService,用eclipse生成的setter是
    setIService(IService iService);而Spring认可的setter是setiService(IService iService);楼主的问题可能就出在这里。另外还是建议不要写iService这样的属性。
      

  4.   

    我也遇到同样的问题,连工程都启动不起来,最后终于搞定:
    struts.xml:
    <action name="test" method="getAll" class="TestAction">
                <result name="success">/success.jsp</result>
            </action>
    applicationContext.xml:
    <beans>
    .....
    <bean id="TestAction" class="presentation.TestAction" >
    <property name="testService"><ref bean="testService"/></property>
    </bean>
    ......
    </beans>在action的class和application.xml中bean id的值一致,就可以找到service了,然后在TestAction中加一属性:
    private TestService testService;
    public void setTestService(TestService testService) {
        this.testService = testService;
    }
      

  5.   

    我也遇到这个问题了,我的action里面class的值和applicationContext里面action的id值是一样的,但是报的错误是找不到class的值。也就是applicationContext的Id值。