我用struts2和spring3搞整合,现在都弄好了。但我发现我要把struts.xml文件去掉改用annotation时就出问题了,因为struts2的action都给spring3管理了,要设一个action会出现找不到这个action的问题。难道struts2和spring3整合了就不好用annotation了吗,求解。另要是有大神随便说明下rest风格的东东要怎么设就更好了。

解决方案 »

  1.   

    struts2的action不要交给spring管理的。spring只需要管理Service和Dao。使用Struts2 convention虽然是零配置了,但是struts.xml还是要保留的吧。
      

  2.   

    不好意思,好久不同讲错了。要在struts.xml里加上<constant name="struts.objectFactory" value="spring" />,将action交给spring管理。
      

  3.   

    这句话已经有了。正是action被spring管了才使得annotation没法用了。
      

  4.   

    原来我struts.xml里有这样的配置,程序是没问题的。
    <action name="showlist" class="showlistAction">
    <result name="error">/error.jsp</result>
    <result name="success">/list.jsp</result>
    </action>
    但现在我想把这个struts.xml文件去掉,成下面这个样子
    @Action(value="showlist")
    public String execute() throws Exception {
    csdnlist = csdnDao.list();
    System.out.println("csdnlist" + csdnlist.size());
    return "success";
    }
      

  5.   

    convention零配置不代表不要任何配置。我一直是使用actionName!method.action弄的。xml里<package>总是要设置的。比如自定义拦截器还是要在这里定义的,在Action里可以用@IntercepterRef()引用。貌似如果你要自定义@Action,还要在Action类上加@ParentPackage("packagename"),packagename对应<package>的name。