标签:
xml based:
<bean id="localRepository" class="com.demo.bean.LocalRepository" scope="session"> <!-- To effects the proxying when used as dependencies by singleton beans. This requires CGLIB --> <aop:scoped-proxy /> </bean>
Java based:
@Component @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public class LocalRepository implements DisposableBean { // TODO @Override public void destroy() throws Exception { // cleanup } }
ScopeProxyMode.TARGET_CLASS means:
Create a class-based proxy (uses CGLIB).
两种写法实现Session Scope的Spring Bean
标签:
原文地址:http://www.cnblogs.com/haibinyuan/p/5070975.html