Spring的JavaConfig:作用域代理

时间:2015-04-05 14:45:10

标签: spring

JavaConfig与此相当的是什么?

<!-- an HTTP Session-scoped bean exposed as a proxy
     that acts as session storage.
-->
<bean id="checkOutCounter" class="org.brightworks.genesis.client.forms.CheckOutCounter" scope="session">
    <!-- this next element effects the proxying of the surrounding bean -->
    <aop:scoped-proxy/>
</bean>

尝试声明这样,但它只是作为一个单身人士

@Bean
public CheckOutCounter checkOutCounter(){
    return new CheckOutCounter();
}

所述xml配置的等价物是什么?

1 个答案:

答案 0 :(得分:14)

对于组件初始化:

@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)

对于@Bean:

@Bean
@Scope(value="session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public CheckOutCounter checkOutCounter(){
    return new CheckOutCounter();
}