wangdgsc0105 2009-10-20 21:27
浏览 255

关于struts1多模块与spring注解

我使用switchAction来处理多模块请求,
想使用spring的注解来管理action,
在spring的配置文件中管理action是可以的,但是使用注解的则不行,不能创建action,
不知道是不是我的配置有问题,或者是有些什么其他的问题,希望哪位能帮我看看,解答一下
我的相关文件内容如下:
web.xml
[code="xml"]

action
org.apache.struts.action.ActionServlet

config
/WEB-INF/struts/struts-config.xml


config/demo
/WEB-INF/struts/struts-config-demo.xml


debug
3


detail
3

0


action
*.do

[/code]
struts-config.xml默认模块配置文件
[code="xml"]






[/code]
struts-config-demo.xml
[code="xml"]





[/code]
Demo1Action
[code="java"]

@Controller("/demo1/demo")
@Scope("prototype")
public class Demo1Action extends DispatchAction {

public ActionForward demo(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    request.setAttribute("message", "这是Demo1模块");
    return mapping.findForward("list");
}

[/code]
DemoAction
[code="java"]
@Controller("/demo")
@Scope("pototype")
public class DemoAction extends DispatchAction {

public ActionForward demo(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    request.setAttribute("message", "这是Demo模块");
    return mapping.findForward("list");
}

}
[/code]
applicationContext.xml
[code="xml"]
<!-- 这是我注释后的配置,如果不使用注解,使用这样的配置则是可以的



-->
[/code]
[b]问题补充:[/b]
忘了补充一点,我使用的是插件是
[code="xml"]



[/code]
[quote]
http://reack.itpub.net/post/1065/22126
蔡华江 (高级程序员) 2009-10-20 采纳为答案 举报作弊
[/quote]
谢谢蔡华江的回答,这个网址我刚才看过了,里面说的是不使用注解的方式来进行配置的,如果我不使用注解,而使用配置文件的话,是没有问题的,但是使用注解,再使用switchAction就不行了,我不知道是为什么,
报的错误是
HTTP Status 500 - No action instance for path /demo could be created
下面是我在jsp页面上写的访问路径
[code="html"]
Demo
Demo1
[/code]

[b]问题补充:[/b]
[quote]sunlightcs (高级程序员) 2009-10-22
[/quote]
谢谢你,你让我成功了一半,默认模块是没有问题了,但是我的那个demo子模块却不行,不知道为什么,希望能帮我解答,谢谢
[b]问题补充:[/b]
[quote]
引用
@Controller("/demo1/demo")

@Scope("prototype")

public class Demo1Action extends DispatchAction {

public ActionForward demo(ActionMapping mapping, ActionForm form,  
        HttpServletRequest request, HttpServletResponse response)  
        throws Exception {  
    request.setAttribute("message", "这是Demo1模块");  
    return mapping.findForward("list");  
} 

说明一点,不要@Controller("/demo1/demo") 这样写,"/demo1/demo"这是这个ACTION交给Spring管理时BEAN的名字,不是路径,最好这样写:@Controller("demo1Action")
sunlightcs (高级程序员) 2009-10-23 采纳为答案 举报作弊
[/quote]
谢谢你的回答,我想再问一下:
如果说这里不写成/demo1/demo,难道这里不是需要和struts配置文件中的相匹配吗?在配置文件中配置的话,访问路径就是bean的name属性值,按说,这里应该也是没有错啊,还有,如果我这里不写成/demo1/demo,而直接写成/demo的话就会与默认模块的访问路径相冲突,刚试了一下,改为/demo1也不行,还是没有action实例被创建,
[b]问题补充:[/b]
[quote]
sunlightcs (高级程序员)
[/quote]
你说的是struts2.struts1不是这样的

  • 写回答

1条回答 默认 最新

  • CaiHuajiang 2009-10-20 21:32
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题