【发布时间】:2016-08-22 09:46:44
【问题描述】:
我的简单域类:
class TestDestroy {
String x
}
还有一项服务:
class TestDestroyService implements DisposableBean {
@Override
void destroy() throws Exception {
TestDestroy d = new TestDestroy(x: "x")
println("Test destroy: ${d.x}")
}
}
如果我从控制器调用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{ ...
这仅发生在领域类中,对于其他 groovy 类,构造函数可以正常工作。如果我用 setter 设置属性,它就可以工作。
对于使用带有映射构造函数的域类并从 destroy() 调用的代码来说,这通常是危险的
设置:
groovy 2.4.4
hibernate4 4.3.6.1
jetty 8.1.9
【问题讨论】:
标签: hibernate grails grails-orm