Announcement Announcement Module
Collapse
No announcement yet.
In Spring MVC, how to pass an HttpSession to a bean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • In Spring MVC, how to pass an HttpSession to a bean?

    Hi all,

    In Spring MVC, how could I pass an HttpSession object to a bean other than a controller such that I could create an instance of that bean based on an attribute stored in the HttpSession. Then, the new instance will be injected to a controller via setter injection.

    Thanks in advance!

    Nathan

  • #2
    The instances of your bean are different and are depending on an attribute in the session. Right?

    What i would do:

    Create a custom factory for your bean and inject this factory (not the bean) into your controller. Then, in your controller, ask the factory for a new object and pass the session as an parameter to your factory. Now do the init work in your factory and the bean will not depend on the session api.

    But why do you need this? Maybe there is a better way.

    Best regards,

    Roman

    Comment

    Working...
    X