2015-04-05 38 views
3

這是什麼JavaConfig相當於?aop的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配置的相同呢?

回答

8

對於組件初始化:

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

對於@Bean:

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

凡根據什麼包是DefaultScopes的? – user962206 2015-04-05 14:56:28

+0

這只是一個字符串常量。你可以用''session'替換它' – 2015-04-05 14:58:04

+0

@ScopedProxy怎麼樣? – user962206 2015-04-05 14:58:44