struts2+spring中action的生命周期问题
来源:互联网 发布:iphone软件更新小红点 编辑:程序博客网 时间:2024/05/16 02:38
将struts2中的action交给spring管理
如果没有指定scope就会出现验证时第一次验证的结果一直存在,导致后面的验证根本没有进行
所以在spring中配置action时要指定scope属性为prototype
<bean id="randomImageAction"
class="cn.link.sgums.action.RandomImageAction" scope="prototype">
这样就ok了
默认的spring的bean的周期是单态的(Singleton)
对于每一次请求不会生成新的实例
Spring里默认情况下,用BeanFactory和ApplicationContext获得的bean实例都是一个。看下面这个例子:
public class HelloBean2 { private String name; private String helloWord; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getHelloWord() { return helloWord; } public void setHelloWord(String helloWord) { this.helloWord = helloWord; } }
Bean的定义:
<bean id="helloBean" class="onlyfun.caterpillar.HelloBean2" singleton="true"> <property name="helloWord" value="test"/> <property name="name" value="Tom"/> </bean>
测试:
ApplicationContext context = new ClassPathXmlApplicationContext("beans-config.xml"); HelloBean2 helloBean1 = (HelloBean2)context.getBean("helloBean"); helloBean1.setName("jack"); System.out.println(helloBean1.getName()); HelloBean2 helloBean2 = (HelloBean2)context.getBean("helloBean"); System.out.println(helloBean2.getName());
输出结果为: jack jack
由此可以看出在Spring容器中,默认情况下,每一个bean只有一个实例。
我们对bean的配置文件做一些修改: 加上了singleton="false" 这个配置,再执行上面的测试,结果为: jack Tom 这时每次去获得helloBean的实例,就是一个新的实例了。(singleton默认是等于true)。
对于Spring2.0,上面的配置可以改成:scope = "prototype" , scope的默认预设值singleton,针对Web应用,scope的值还可以设置为“request”,"session","globalSession"分别对应web的请求阶段,会话阶段,web应用程序阶段。
- struts2+spring中action的生命周期问题
- struts2+spring中action的生命周期问题
- SSH:Could not find action or result提及struts2+spring整合中action的生命周期
- struts2 的action的生命周期
- Struts2+Spring集成中Action的管理
- Struts2+Spring集成中Action的管理
- Struts2的Action之生命周期
- struts2.0中Action的对象生命周期详解!!
- 关于struts2中与Spring中Action对象创建的问题
- Struts2中action之间的跳转问题
- struts2中action不执行的问题
- struts2 中action执行两次的问题
- 关于struts2中<s:action>的问题
- Struts2中action之间的跳转问题
- Struts2中action之间的跳转问题
- struts2中action 提交两次的问题
- struts2与spring集成时,关于Action类中成员bean自动注入的问题
- struts2与spring集成时,关于Action类中成员bean自动注入的问题
- 给U盘加个回收站
- sp dip px
- 常用正则表达式
- SqlParameter 基本用法
- U盘装系统之Linux篇
- struts2+spring中action的生命周期问题
- SQL 查询表结构
- Maven安装于配置
- SQL备份
- VC++执行多条dos命令方法
- linux 驱动模块编译
- C# 计算时间差
- VS2010 自动关闭的问题解决方法
- #ifndef __IPHONE_X_X