Announcement Announcement Module
Collapse
No announcement yet.
reinject transient properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • reinject transient properties

    Is it possible to inject dependencies into a bean that that has been deserialized based on what I configured in the spring xml config file?

    I have a bean which contains references to services. Those references I've made transient so that they are not serialized. When I deserialize the bean's, I would like to reinject all the services that were injected to begin with.

    Cameron

  • #2
    You would need to intercept the deserialisation. How are you serialising/deserialising it, or what *causes* the serialisation?

    Comment


    • #3
      I would like to see an elegant answer to this problem too.

      Some of my beans will be serialized when the HttpSession is serialized (on server restart / clustering maybe later).

      And that's the problem, there is no way to listen to serialization/deserialization. Only "readResolve" in the serialized bean itself.
      But since the bean should not know Spring this is not a real solution.

      Currently I'm helping myself with a Pseudo-Singleton-Registry, but some kind of real listener-mechanism would be nice.

      Comment


      • #4
        I agree with yatesco - intercepting the deserialization (with after return) would allow spring to get a valid object and then reinject everything in there.
        It's the cleanest and most decoupled alternative in my opinion.

        As for doing this outside the Spring context - I think it's a contradiction in terms - Spring should inject the properties but outside the Spring context?
        If you will not have dependecies on the Spring API, you'll have then on your pseudo-singleton-registry that will act as the bridge between the Spring context and container.
        It's simply a dependecy that has to be satisfied one way or another.

        Comment


        • #5
          Uhm, maybe I did not make things as clear as I should have ;-)

          Of course I want to do the injection of transient properties inside a spring-environment.
          It's okay for me, if an Advice depends on the Spring API to lookup dependencies and rewire the serialized/deserialized bean.

          Only the bean itself should not depend on the Spring API (and also not on my pseudo-singleton-registry, of course).

          Now I'm thinking about, how to intercept deserialization. Any hints, how such a joinpoint-definition could look like?

          thx

          Comment


          • #6
            Take a look in the reference manual - just make a standard interceptor which will wrap your bean and that's it.

            Comment


            • #7
              I face the same problem and I've described my case in a different thread :
              http://forum.springframework.org/showthread.php?t=18753

              If anyone succeeded in solving this problem, please post your solution.

              Thanks
              Last edited by robyn; May 14th, 2006, 07:15 PM.

              Comment

              Working...
              X