Given a spring bean that is configured with session scope such as:
@Component
@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS,value=WebApplicationContext.SCOPE_SESSION)
public class SomeBean {
}
Is there some way to control the name that Spring will store the bean under in the http session?
By default spring seams to use the session key scopedTarget.someBean
is there anything I can add to the annotations to explicitly specify the attribute name in the Session?
I'd use:
@Component (value="mySpecialName")
@Scope (value="session")
You cannot. The scopedTarget
part is hardcoded in the scoped proxy creation in Spring. So without rewriting parts of the framework that simply isn't possible.
The name is hardcoded in the ScopedProxyBeanDefinitionDecorator
which delegates to the ScopedProxyUtils
.
The fact that you use a scoped proxy is something internal for the framework. You probably want to use it to store something in the session and retrieve it in a page or something like that. Don't, just expose the regular bean which will delegate to the proper scoped instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With