struts2 spring集成时struts.xml文件中action的class属性值意义
来源:互联网 发布:时间机器字幕制作软件 编辑:程序博客网 时间:2024/05/01 20:47
struts2单独使用时action由struts2自己负责创建;与spring集成时,action实例由spring负责创建。这导致在两种情况下struts.xml配置文件的略微差异。
假如:LoginAction在包cn.edu.jlu.cs.action中。
1. struts2单独使用时,action的class属性为LoginAction的全路径名,如下:
...
<action name="login" class="cn.edu.jlu.cs.action.LoginAction">
<result name="studentSuccess">
/student/studentindex.jsp
</result>
...
2. struts2与spring集成时,class属性是spring的applicationContext.xml中配置的bean的id属性值。
---------------------------------------------------------------------------------------
//struts.xml
...
<action name="login" class="LoginAction">
<result name="studentSuccess">
/student/studentindex.jsp
</result>
...
----------------------------------------------------------------------------------------
//applicationContext.xml
...
<bean id="LoginAction" class="cn.edu.jlu.cs.action.LoginAction" />
...
----------------------------------------------------------------------------------------
struts2-spring-plugin-2.1.6.jar这个插件在产生action的时候,会自动的按照名字把action的属性注入进去,
即使不在spring配置文件中为相关的action(bean)注入属性或者在action类中用注解注入,
它也会按照action类中属性的名字从当前容器(??Spring)中找有没有这个名字的bean并注入进来,或者显示的给定一个名字注入。
所以action的id(spring配置文件中的)不要和它类里边的变量名相同
如果在struts.xml文件中配置action的class是指向action的实际类,那么action的产生由struts控制,
此时action类中的相关变量会按照名称从容器中注入一个相应的bean,如果找不到对应名称的bean,一旦调用这个action就会出错,
但是如果此时为变量加上一个@Resource注解,struts容器产生过action后就会从Spring容器中找相应的bean注入。
如果class指向的是一个伪控制器(对应spring配置文件中action的bean),那么action的产生由spring控制。
此时action类中的相关变量··必须··用注解@Resource或者xml的方式自定义注入相应的bean,不象之前会按照名字从spring容器中自动查找注入bean,
否则程序运行出错
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/alixa/archive/2011/04/13/6319468.aspx
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时struts.xml文件中action的class属性值意义
- struts2 spring集成时action的class属性值意义
- struts2 spring集成时action的class属性值意义
- struts2与spring集成时action的class属性值意义
- struts2中action的class属性值意义
- struts2与spring集成时action的class属性设置
- 1、看看你struts.xml文件中action中对应的class属性的值是否可以在Spring的配置文件中找到对应的id值。
- struts-config.xml中action元素的attribute属性的意义
- 阿翔编程学-struts-config.xml中action元素的attribute属性的意义
- HDU--2004 -- 成绩转换
- Unexpected token "name" of value "with" ("end of statement block" expected) in
- [php]通过http post发送json数据
- oracle11g客户端+PlsqlDeveloper连接远程oracle服务器方法
- 利用WNet系列函数枚举和映射网络资源
- struts2 spring集成时struts.xml文件中action的class属性值意义
- C或C++中函数的参数传递包括:值传递、指针传递、引用传递
- linux入门
- 在eclipse中将android项目生成apk并且给apk签名
- 对iOS系统键盘的hack以及注意事项
- JS中使用Ajax获取的数据赋值不了问题的解决方案
- poj 2253 Frogger(dijkstra)
- java心得
- #define命令的一些高级用法