struts2整合spring--spring beans对Action类的管理

来源:互联网 发布:交女友软件 编辑:程序博客网 时间:2024/05/16 18:02

struts2文档中说:由struts的name元素对应spring的id元素。


When an object is to be created, it uses the class attribute in the Struts configuration to correspond to theid attribute in the Spring configuration.


测试如下,applicationContext.xml中默认采用component-scan自动遍历beans。在调用Action的方法中加入以下两行代码。

System.out.println(this);System.out.println(ApplicationContextHolder.getApplicationContext().getBean("loginAction"));

情况一:

struts.xml采用包.类名称的形式

<action name="login" class="fpa.action.login.LoginAction" method="login">            <result >jsp/main.jsp</result></action>

Action类采用默认注释

@Componentpublic class LoginAction{...}


连续两次,访问此action,测试结果:

fpa.action.login.LoginAction@7ea991e0
fpa.action.login.LoginAction@2ea84a17
11
fpa.action.login.LoginAction@10cfc2e3
fpa.action.login.LoginAction@2ea84a17
00

结论一:Action类并没有交由spring管理,而是由struts自己new的。