8

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?

user962206
  • 15,637
  • 61
  • 177
  • 270

1 Answers1

16

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();
}
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145