Vaadin视图范围对象销毁问题



我使用Vaadin 8.15版本(vaadinCompatibilityVersion=7.7.11(。我使用Oracle JVM Java jdk11。

我有这个代码:

public class MyComponent extends CustomComponent {
@PreDestroy
public void destruction(){
//writing log
...
}
}
public class MotherComponent extends CustomComponent{
...
protected MyComponent myComponent;
...
public MotherComponent(){
super();
myComponent = new MyComponent();
}
...
}
...
}

垃圾回收完成后,myComponent不写日志。如果myComponent在具有vaadin视图作用域的MotherComponent中注入了Spring,则编写日志。为什么?我预计这两个案例的输出应该是相同的,但事实并非如此。

我预计这两个案例的输出应该是相同的,但事实并非如此。

@PreDestroy是一个Spring特性,仅用于Spring托管的bean。当您使用new关键字来创建组件的实例时,您需要手动管理该实例,而不是让Spring来执行

相关内容

最新更新