关于Vaadin当前显示的对象序列化的NotSerializableException [英] NotSerializableException on serialization of objects currently shown by Vaadin

查看:122
本文介绍了关于Vaadin当前显示的对象序列化的NotSerializableException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想序列化当前由Vaadin显示的Object时,我得到一个NotSerializableException。

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

结构是这样的:

Vaadin UI< --- serialize / deserialize ---> Hibernate / JPA Postgres数据库

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

Vaadin显示从数据库请求的对象通过IPC,
但是当我操纵对象并希望通过
再次保存它并将其发送到控制器时我得到以下例外:

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)

我试过:

请求 - >操作 - >保存|作品

Request -> manipulate -> Save | works

请求 - >在Vaadin中显示 - >在Vaadin中操作 - >保存|不起作用

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

为什么Serializer想要AnnotationConfigEmbeddedWebApplicationContext并且有解决方法?我可以事先将其删除吗?

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

推荐答案

Spring组件通常不可序列化(或根本不应序列化)。

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

在与Vaadin UI链接的Vaadin组件中注入Spring组件非常棘手,因为它们应该被声明为 transient 并且重新 - 反序列化后填充..

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..

我写了一个小型库 jdal-aop 使用spring-aop可序列化代理来简化流程。

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

例如

public class MainLayout extends VerticalLayout {

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

它可能对您有用。

这篇关于关于Vaadin当前显示的对象序列化的NotSerializableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆