两种写法实现Session Scope的Spring Bean

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).

posted @ 2015-12-23 19:02  hbyuan27  阅读(341)  评论(0编辑  收藏  举报