Announcement Announcement Module
Collapse
No announcement yet.
Singleton bean in session scope bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Singleton bean in session scope bean

    Hi all,

    I'm using a session scoped bean in a Struts 2 application. This session bean has a dependency to a back-end singleton service. I declared this singleton service as transient in the session bean class (because the singleton does not need to be serialized).

    It worked good so far, but I was just wondering if it was not risky to do so. Indeed, if the session bean is serialized and then unserialized, will the singleton be re-injected?

    Any hint welcome

  • #2
    Hi,

    this will not be done. Because the while deserializing the bean, the new() constructor is called outside the beanfactory. One way to re-wire the bean is to use @Configurable

    Have a look here

    best rgds
    agim

    Comment


    • #3
      Under what circumstances would your session scoped bean be serialized/deserialized? In a failover scenario? If your scoped bean needs to be serializable then @Configurable is the only way I can think you would implement this. But if possible you should find a way to not make your bean serializable. That way only Spring controls the lifecycle of your bean, making @Configurable not needed.

      Comment


      • #4
        thank to both you for your reply.

        Originally posted by wpoitras View Post
        Under what circumstances would your session scoped bean be serialized/deserialized? In a failover scenario? If your scoped bean needs to be serializable then @Configurable is the only way I can think you would implement this. But if possible you should find a way to not make your bean serializable. That way only Spring controls the lifecycle of your bean, making @Configurable not needed.
        There's no need of recovery (this is not critical if the user must log on again after a server failure), I only need the bean to be session scoped. I don't know much about session handling mechanics in web containers but I fear the web container could serialize the bean for any reason (ex.: need of memory) between two requests. If this scenario cannot happen (i.e. the session bean will never be serialized), well, there's no problem anymore

        Comment


        • #5
          Originally posted by arno View Post
          I fear the web container could serialize the bean for any reason (ex.: need of memory) between two requests.
          No reason to fear. I would not consider breaking the session serializability a good approach but unless the session needs to survive a server restart or some session replication (e.g. in a cluster) there is no risk.

          Joerg

          Comment

          Working...
          X