似乎在ActionForm里面也有个setServlet方法,你重写这个方法
import javax.servlet.ServletContext;
import org.apache.struts.action.ActionServlet;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class UserForm extends ActionForm {
private UserService service;
   @Override
   public void setServlet(ActionServlet servlet) {
ServletContext context = servlet.getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
UserService service = (UserService)ctx.getBean("userService");
super.setServlet(servlet);
   }
get...set...
......
}

解决方案 »

  1.   

    写的有点问题,再发一下
    import javax.servlet.ServletContext;
    import org.apache.struts.action.ActionServlet;
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;
    public class UserForm extends ActionForm {
    private UserService service;
       @Override
       public void setServlet(ActionServlet servlet) {
        ServletContext context = servlet.getServletContext();
        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
        this.service = (UserService)ctx.getBean("userService");
        super.setServlet(servlet);
       }
    get...set...
    ......
    }