Hi,
I am interested in using the request and/or session scoped beans functionality for a project I'm working on and saw the documentation specifically for user preferences in the spring doc.
My question is how would I create and initialize this bean before putting it in the session (or request scope) so that it can be used by other components in the spring mvc project ?
So lets say when every request is received there are attributes of the authenticated user making the request set in request headers. What I would like to do is before the request hits any of my spring controllers, to be able to pull out the values of all of the relevant headers and create a User object and place it in the request scope. This way when all of my controllers and any class called downstream needs to access details of the user, all they have to do is pull out the User request scope bean and access its values. How would I go about doing this ? I know how to dependency inject this bean into my controllers but do I fire the initialization logic that reads the headers and creates the bean instance and how do I make sure this gets set in the request scope before the controllers are called ?
I feel the dependency injection of session and request scope beans is very powerful but where would I put in logic to have these beans created and placed in the request / session ?
Take the case of user preferences described in the spring doc. I see the value of creating a session scoped bean and injecting this into all the classes that need it. But how do I fire off the logic that creates this UserPReference bean in the first place ? i.e. a users preferences is typically a db operation where I would query the db for the various preferences set for this user. How would I make sure this logic fires on session creation to create the UserPreference bean before putting it in the session for access by other classes ?
Any insights would be much appreciated.
Thanks !


Reply With Quote
