Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JavaConfig of aop:scoped proxy

Tags:

spring

What is the JavaConfig equivalent of this?

<!-- 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>

Tried declaring it like this but it only acts as a singleton

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

What is the equivalent of the said xml config?

like image 834
user962206 Avatar asked Apr 05 '15 14:04

user962206


1 Answers

For component initialization:

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

For @Bean:

@Bean
@Scope(value="session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public CheckOutCounter checkOutCounter(){
    return new CheckOutCounter();
}
like image 155
Evgeni Dimitrov Avatar answered Sep 30 '22 14:09

Evgeni Dimitrov