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構造函數在銷燬後不起作用。 –