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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程