struts2和spring3整合后,为什么找不到action了

想用spring来管理struts2的action,因为还要向action中注入service,但用@Controller("/roleList")注解后,却找不到action了,这是为何喃?

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xxx.action.BaseAction;
import com.xxx.common.bean.PaginationReturnBean;
import com.xxx.common.constant.ConstantDefine;
import com.xxx.common.security.Description;
import com.xxx.common.security.Privilege;
import com.xxx.manage.bean.RoleQueryBean;
import com.xxx.manage.entity.Role;
import com.bizex.manage.service.RoleService;
import com.opensymphony.xwork2.ModelDriven;

@Controller("/roleList")
@Scope("prototype")
@ParentPackage("manage")
@InterceptorRef("manageStack")
public class RoleListAction extends BaseAction implements ModelDriven {

@Resource(name = "roleService")
private RoleService roleService;

private static final long serialVersionUID = -3029290129233743984L;

private RoleQueryBean roleQueryBean = new RoleQueryBean();

private PaginationReturnBean<Role> roles = new PaginationReturnBean<Role>();// 查询角色列表的输出

@Action(results={@Result(location="manage/role_list.jsp")})
public String execute() throws Exception {
    roles = roleService.getRoleList(roleQueryBean);
    return SUCCESS;
}

public RoleQueryBean getModel() {
    return roleQueryBean;
}

public PaginationReturnBean<Role> getRoles() {
    return roles;
}

public void setRoles(PaginationReturnBean<Role> roles) {
    this.roles = roles;
}

}

1 首先,你要确定你的struts2有和spring集成成功,
如何确定:
使用@Scope来定义作用范围,分别定义成单例和多例。然后在你的action中
输出对象的hashcode,看看是否生效,如果生效,证明集成是成功的。否则
肯定是不成功的,依然是由struts帮你实例化action。

2。如何集成:
并不应该认为标上注解就能集成成功的。
首先你要在struts配置文件里说明,对象产生的方式是用spring来为你产生。
即设置 struts.objectFactory =spring
[color=red]其次:将action配置里的class属性设置为action bean名称就是你的@Controller("name") 而不是类的完整路径 (重要)[/color]

这样就可以成功了。当然前提是你其他的配置没问题。

那Controller和Action你到底想用哪一个来控制你的请求呢?

@Controller和@Action你想用哪个来控制你的请求啊。不能乱用。

Spring injection 和Spring mvc可是两回事啊。用Action怎么就不能注入Service。那你用的哪个Servlet来转发控制你的请求的呢?

建议你看看Struts2 书籍