In your case, you do not need a session area. You just need an instance of the specialized oneton provider
interface CustomProvider<E> {
public E get();
}
@Configuration
class TestConfig {
@Bean
public CustomProvider<Integer> factory() {
return new CustomProvider<Integer>() {
@Override
public Integer get() throws BeansException {
return new Random().nextInt();
}
};
}
}
And enter it
@Inject
private CustomProvider<Integer> factory;
I missed that you want the same value for the session. See Emerson answer for this.
In general, for a beans session:
In a class, @Configurationyou can provide a method @Beanthat has a session scope.
@Bean
@Scope(value = WebApplicationContext.SCOPE_SESSION )
public SomeBean someBean() {
return new SomeBean();
}
@Scope @Component.
XML
<bean id="someBean" class="com.example.SomeBean" scope="session" />