6

I have a spring MVC web application, I have java classes that I have annotated with @Scope("session") and currently running it on tomcat. The classes annotated with the scope store user information that I don't want to lose in case the server crashes. So how do I persist the session together with all the flow information and the user data stored in the @Scope("session") beans into an external DB (a custom noSQL DB) so that when the server crashes, the user will seamlessly be transferred to another server and all the data and info and beans restored from the external DB to the new server without the user even noticing anything. I don't want to use tomcat persistence and I also don't want to use Redis.

Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
tigg
  • 107
  • 8
  • 1
    Implement your own `org.springframework.session.SessionRepository`, no? `RedisOperationsSessionRepository` is an implementation of this interface. You don't want to use it - make on of your own. – nolexa Jan 22 '16 at 21:39
  • I was actually looking at that but the question is, when spring-session saves it into the repository, will it save just the http session or will it save everything including the data in the spring beans? – tigg Jan 22 '16 at 22:10
  • 1
    Maybe you're asking a wrong question. As it seems, it does not matter how to persist the session because it will be upp to your implementation to decide. The real question is if Spring is going to save the entire session context using the provided persistence mechanism. Does it do that with Redis? I don't know if it's happening. – nolexa Jan 22 '16 at 22:42
  • Exactly, that's what I meant. I saw some implementation with redis using Spring boot but its not clear if that is what redis is doing. Do you know if its possible to persist the entire session context? – tigg Jan 22 '16 at 22:52
  • 1
    No, I don't know that, sorry. But it should be possible to trace what's going on by configuring a dummy `SessionRepository` and observing what data it gets when it's asked to persist a session. Something like that. Unless someone answers your question here. – nolexa Jan 22 '16 at 23:01
  • 1
    The point is that Springs SessionScoped Beans are NOT stored in the Servlet-Session, therefore saving the Servlet-Session is not enogth – Ralph Jan 23 '16 at 08:10
  • 1
    Just confirmed. Saving a proxy scoped session bean of type ShoppingCart will place `scopedTarget.shoppingCart: com.my.package.path.ShoppingCart@49d07a00` as an attribute inside HttpSession but... the actual bean itself does not live inside HttpSession. I persisted the entire session but when I tried to retrieve the sesson the contents of my 'shoppingCart' were lost. This is a good question for Rob Winch or somebody from the spring team to answer. – Selwyn Jan 23 '16 at 19:30
  • Do you happen to know how I can contact Rob Winch or the Spring team about this? I visited a contact us page on the Pivotal website and used the contact us form but the number of characters to enter in the comment field was very limited and i couldn't say much there so I pasted a link to this stack overflow question there. But i am not sure if this is the best way to contact them, I was hoping I can find a contact email somewhere but i couldn't find any. – tigg Jan 24 '16 at 16:22
  • @tigg they monitor stackoverflow posts. Somebody will get to it. – Selwyn Jan 25 '16 at 10:40

0 Answers0