weixin_42470122 2011-08-16 21:24
浏览 414
已采纳

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;
}

}

  • 写回答

5条回答 默认 最新

  • icezx 2011-08-18 15:43
    关注

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

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!