gpt4 book ai didi

hibernate - map 构造函数不适用于应用程序销毁

转载 作者:行者123 更新时间:2023-12-02 14:49:39 26 4
gpt4 key购买 nike

我的简单域类:

class TestDestroy {
String x
}

和服务:
class TestDestroyService implements DisposableBean {
@Override
void destroy() throws Exception {
TestDestroy d = new TestDestroy(x: "x")
println("Test destroy: ${d.x}")
}
}

如果我从 Controller 调用 destroy()方法,一切都很好,并且得到输出:
Test destroy: x

在应用关闭时调用 destroy时出现问题,输出为:
2016-08-22 11:20:14.186:INFO:t.1:Destroying Spring FrameworkServlet 'grails'
Test destroy: null
2016-08-22 11:20:14.487:INFO:t.1:Closing Spring root WebApplicationContext
2016-08-22 11:20:14.496:INFO:oejsh.ContextHandler:stopped o.e.j.w.WebAppContext{ ...

这仅在域类中发生,对于其他常规类,构造函数将按预期工作。如果我使用setter设置属性,则可以使用。

对于使用带有 map 构造函数的域类并从 destroy()调用的代码,这通常很危险

建立:
groovy 2.4.4
hibernate4 4.3.6.1
jetty 8.1.9

最佳答案

为什么不使用grails bootstrap init和destroy。

def init = {
//init code here
}

def destroy = {
//destroy code here
}

在destroy方法中,您可以执行任何操作。此外,如果要隔离代码,请创建destroy服务,然后调用该服务。

关于hibernate - map 构造函数不适用于应用程序销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39076268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com