spring2.0中的session作用域被注入
2007-09-11 18:47
141 查看
样例1:
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
第一个例子: 如果session失效,userManager仍将保留userPreferences实例!
userManager直接将userPreference的引用拷贝了一份到自己的特定地址上!销毁了原来的实例,而拷贝后的实例依赖存在!
样例2:
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="userService" class="com.foo.SimpleUserService">
<property name="userPreferences" ref="userPreferences"/>
</bean>
加了<aop:scoped-proxy />,这个的作用是代理这个实例
第二个例子: session失效,则userPreferences失效. 单例的userManager保存的是userPreference的代理实例!
这个代理实例不是singleton的,也不是跟随着userPreferences的.它是随着session创建而创建... 如果session销毁,代理实例就无法访问到userPreference了!
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
第一个例子: 如果session失效,userManager仍将保留userPreferences实例!
userManager直接将userPreference的引用拷贝了一份到自己的特定地址上!销毁了原来的实例,而拷贝后的实例依赖存在!
样例2:
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="userService" class="com.foo.SimpleUserService">
<property name="userPreferences" ref="userPreferences"/>
</bean>
加了<aop:scoped-proxy />,这个的作用是代理这个实例
第二个例子: session失效,则userPreferences失效. 单例的userManager保存的是userPreference的代理实例!
这个代理实例不是singleton的,也不是跟随着userPreferences的.它是随着session创建而创建... 如果session销毁,代理实例就无法访问到userPreference了!
相关文章推荐
- spring 当中session或者request作用域注入单例bean的问题
- 【Spring】--OpenSessionInViewFilter 的配置及作用
- ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题
- java框架spring中的opensessioninview有什么作用
- session监听器中不能使用spring依赖注入
- java框架spring中的opensessioninview有什么作用
- java框架spring中的opensessioninview的作用
- 详细解析Spring事务的配置和OpenSessionInview的作用
- spring注入方式、配置项及作用域、生命周期、Aware接口、自动装配
- 使用Spring2.0的annotation方式进行依赖注入检查
- ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题
- Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
- Spring 2.0中集合对象注入的复用
- MyBatis-Spring整合 注入SqlSessionTemplate
- web.xml中配置Spring的OpenSessionInViewFilter的作用
- spring之注入不同作用域之间的bean
- spring 基础学习,引用、作用域、注入、依赖等
- Spring (二)依赖注入原理 , bean 作用域, 其他配置
- 详解spring 依赖注入的作用
- Spring 笔记 - @SessionAttribution和@ModelAttribute的作用