vaadin / spring

Spring integration for Vaadin
https://vaadin.com/start
176 stars 101 forks source link

SpringUIProvider's webApplicationContext field is not serializable #74

Closed vaadin-bot closed 8 years ago

vaadin-bot commented 8 years ago

Originally by johannes.tuikkala on 2016-01-13 09:02:40 +0200


org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
        - field (class "com.vaadin.spring.server.SpringUIProvider", name: "webApplicationContext", type: "interface org.springframework.web.context.WebApplicationContext")
        - object (class "com.vaadin.spring.server.SpringUIProvider", com.vaadin.spring.server.SpringUIProvider@d30bfca)
        - custom writeObject data (class "java.util.LinkedList")
        - object (class "java.util.LinkedList", [com.vaadin.spring.server.SpringUIProvider@d30bfca])
        - field (class "com.vaadin.server.VaadinSession", name: "uiProviders", type: "class java.util.LinkedList")
        - root object (class "com.vaadin.server.VaadinSession", com.vaadin.server.VaadinSession@6241ff1a)
        at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:52)
        at org.springframework.data.redis.core.AbstractOperations.rawHashValue(AbstractOperations.java:146)
        at org.springframework.data.redis.core.DefaultHashOperations.putAll(DefaultHashOperations.java:128)
        at org.springframework.data.redis.core.DefaultBoundHashOperations.putAll(DefaultBoundHashOperations.java:85)
        at  ...

Discussion from Skype: [13/01/16 08:48:42] Johannes Tuikkala: It seem like that this is the culbrit for the serialization issue in hte SpringUIProvider private final WebApplicationContext webApplicationContext; [13/01/16 08:50:19] Leif Åstrand: The solution in that case is most likely to make the field transient and non-final and add a custom private void readObject(java.io.ObjectInputStream stream) method that restores the WebApplicationContext reference from somewhere [13/01/16 08:52:44] Leif Åstrand: There might also be other classes that hold references to WebApplicationContext or some other non-serializable spring class. Those will show up one after the other as you fix the previous one :)

Related ticket: #18164

Related StackOverflow thread: http://stackoverflow.com/questions/29388542/notserializableexception-on-serialization-of-objects-currently-shown-by-vaadin

I will try to make a test application for this, where this is easily reproducible.


Imported from https://dev.vaadin.com/ issue #19462

vaadin-bot commented 8 years ago

Originally by johannes.tuikkala on 2016-01-13 16:28:17 +0200


Attachment added: vaadin-demo.zip (29.2 KiB) Test application for reproducing the issue

vaadin-bot commented 8 years ago

Originally by KLHauser on 2016-02-12 12:26:06 +0200


I have updated the SpringUIProvider (see here https://github.com/khauser/microservices4vaadin/tree/master/microservices/frontend/src/main/java/com/vaadin/spring/server) and amazingly it works now ;). But now the UIDL-POSTs fail in line "UI uI = session.getService().findUI(request);" in "com.vaadin.server.communication.UidlRequestHandler" because the uIs-map it VaadinSession is empty.

Do you have any hint how to also come over this issue?

vaadin-bot commented 8 years ago

Originally by mthomas on 2016-05-10 16:30:12 +0300


I also faced this issue today when tying to setup vaadin session clustering on AWS using DynamoDB. This issue has to be fixed for session clustering to work correctly. Please fix asap! For the record, I'm using Vaadin 7.6.5

vaadin-bot commented 8 years ago

Originally by KLHauser on 2016-06-28 19:05:17 +0300


After some time now I was also able to come around the UIDL-POST failures by updating the VaadinSession (containing the right UI/s) stored in Redis. For this I just updated the saveDelta-function in the package org.springframework.session.data.redis.RedisOperationsSessionRepository.

But that's just a workaround.. For me it seems there's some kind of bug in the vaadin-spring-session connection where VaadinSession is not updated after it gets it UIs (in UIInitHandler).

vaadin-bot commented 8 years ago

Originally by KLHauser on 2016-07-21 19:09:15 +0300


There is now a pull request: https://github.com/vaadin/spring/pull/32

With jdal's SerializableProxy I was able to come around all other deserialization problems I had.

vaadin-bot commented 8 years ago

Originally by Artur- on 2016-08-31 14:45:52 +0300


Fixing this might be easiest by implementing #12501 so that UIProviders could listen to session activation, and in the activation event listener lookup the spring context

vaadin-bot commented 8 years ago

Originally by Artur- on 2016-09-01 09:49:23 +0300


Simple fix in https://dev.vaadin.com/review/#/c/14303

vaadin-bot commented 8 years ago

Originally by KLHauser on 2016-09-06 22:41:15 +0300


SpringUIProvider okay but there is also a SpringViewProvider:

org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
    - field (class "com.vaadin.spring.navigator.SpringViewProvider", name: "applicationContext", type: "interface org.springframework.context.ApplicationContext")
    - object (class "com.vaadin.spring.navigator.SpringViewProvider", com.vaadin.spring.navigator.SpringViewProvider@55074169)

Could an analog fix also be applied there?

vaadin-bot commented 8 years ago

Originally by Artur- on 2016-09-07 11:17:51 +0300


Tracked in https://github.com/vaadin/spring/issues/35

jorginius commented 7 years ago

SpringUIProvider's applicationContext field is not serializable too because it holds a reference to the servletContext

pleku commented 7 years ago

Hello @jorginius , very nice catch and that has actually been just fixed with https://github.com/vaadin/spring/commit/47e2ac24a73005d7a15f296e1ea5b1dffc9374a0 and is included in 1.1.1 released today.

scipionyx commented 7 years ago

remove from the views any @autowire reference to the spring context