1
我的简单域类:地图的构造不会对应用程序的工作摧毁
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
在应用sh上调用destroy
时出现此问题utdown,输出为:
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来设置属性,它就会起作用。
它一般针对使用域类地图的构造,并从destroy()
设置称为码危险:
groovy 2.4.4
hibernate4 4.3.6.1
jetty 8.1.9
destroy方法被执行,所以我不需要从bootstrap调用它。 DisposableBean的'destroy()'回调方法更加可读,是Spring实现正常关闭的标准方式。问题是Groovy的Map构造函数在销毁后不起作用。 –