Spring中的aop:scoped-proxy
2014-06-04 11:20
281 查看
首先看一下Spring文档上的两个例子对比:
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
前一个例子没有使用<aop:scoped-proxy/>,并且userManager是singleton,所有userManager仅被初始化一次,并且其属性userPreferences也仅被注射一次。当session失效后,userManager仍将保留userPreferences实例。但后一个例子则不一样,userManager的属性userPreferences指向的是com.foo.UserPreferences实例的代理,当session过期后,userManager的属性userPreferences自然也不能再使用。网上有人解释说,这个代理只随着session的创建而创建,销毁而销毁。
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session"/>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
<bean id="userPreferences" class="com.foo.UserPreferences" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="userManager" class="com.foo.UserManager">
<property name="userPreferences" ref="userPreferences"/>
</bean>
前一个例子没有使用<aop:scoped-proxy/>,并且userManager是singleton,所有userManager仅被初始化一次,并且其属性userPreferences也仅被注射一次。当session失效后,userManager仍将保留userPreferences实例。但后一个例子则不一样,userManager的属性userPreferences指向的是com.foo.UserPreferences实例的代理,当session过期后,userManager的属性userPreferences自然也不能再使用。网上有人解释说,这个代理只随着session的创建而创建,销毁而销毁。
相关文章推荐
- Spring——<aop:scoped-proxy/>理解
- Spring中的aop:scoped-proxy
- 解决异常java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget
- Spring三种切面 <aop:aspectj-autoproxy/><aop:config></aop:config> <aop:scoped-proxy/>
- 挖一挖Spring的 <aop:scoped-proxy/>
- Spring4.3.x 浅析xml配置的解析过程(11)——解析aop命名空间之scoped-proxy标签
- Spring中的aop:scoped-proxy
- java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget
- java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget(Ljava/lan
- Spring-AOP标签scoped-proxy
- 【Spring学习19】作用域:使用代理<aop:scoped-proxy/>
- SpringAop源码情操陶冶-AspectJAwareAdvisorAutoProxyCreator
- 【spring】IllegalArgumentException Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误
- Spring AOP之 java 动态代理(Proxy 与 InvocationHandler)理解
- spring aop 错误解决无法查询到internalAutoProxyCreator
- Java教程 - Spring, AOP, Proxy
- Spring配置项之<aop:aspectj-autoproxy />
- Spring的代理模式及Spring AOP-JDKDynamicAopProxy
- Spring学习笔记 —— AOP标签详解(<scoped-proxy>)
- spring配置文件加<aop:aspectj-autoproxy/>后无法启动listener【解决方案】