Maybe I'm misunderstanding your question.
Your ICurrentLocale
bean should be something like
@Component
@Scope(value = "user", proxy-mode = "ScopedProxyMode.TARGET_CLASS")
public class CurrentLocaleImpl implements ICurrentLocale {
...
}
or the corresponding @Bean
or XML configuration.
With such configuration, Spring will create a proxy for your injection target. In other words, in
@Autowired
private ICurrentLocale currentLocale;
you won't have a CurrentLocaleImpl
object, you'll have a proxy object that has a reference to the underlying BeanFactory
.
5.Call some methods on foo.
My problem is that in point #5, the autowired
ICurrentLocale
bean is still the same despite the fact that a new bean has created in the user's scope.
When you invoke a method on the proxy bean, the proxy will attempt to retrieve an actual CurrentLocaleImpl
object from the BeanFactory
using your Scope
implementation and then delegate the method call to that object. Effectively, you'll be using either the proper object, the default object, or throwing an exception.