NotSerializableException on serialization of objects currently shown by Vaadin

僤鯓⒐⒋嵵緔 提交于 2020-01-11 14:16:46

问题


I get a NotSerializableException when I want to serialize an Object that is currently shown by Vaadin.

The structure is like this:

Vaadin UI <--- serialize / deserialize --- > Hibernate/JPA Postgres Database

Vaadin shows objects that are requested from the Database via IPC, but when I manipulate the object and want to save it again by serializing it and sending it over to the controller I get the following Exception:

java.io.NotSerializableException: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
	at java.util.LinkedList.writeObject(LinkedList.java:1118)
	at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)

I tried to:

Request -> manipulate -> Save | works

Request -> show in Vaadin -> manipulate in Vaadin-> Save | doesn't work

Why does the Serializer want to AnnotationConfigEmbeddedWebApplicationContext and is there a workaround? Can I remove it beforehand?


回答1:


Spring components are usually not serializable (or should not be serialized at all).

Injecting Spring components in Vaadin components linked to a Vaadin UI is tricky because them should be declared as transient and re-populated after deserialization..

I wrote a small library jdal-aop to ease the process, using spring-aop serializable proxies.

for example

public class MainLayout extends VerticalLayout {

    @Autowired
    @SerializableProxy  // make this Dao serializable
    private CustomerDao customerDao;
} 

It could be useful for you.



来源:https://stackoverflow.com/questions/29388542/notserializableexception-on-serialization-of-objects-currently-shown-by-vaadin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!