I have noticed some things about the way that the 'PostDestroy' annotated methods seem to get invoked or not, and was just wondering if someone could confirm what I am seeing.
I am running Spring Batch 2.0.0/Spring2.5.6 in an ordinary JVM. I have a Parent/root application context, which has one child application context.
'PostDestroy' annotated methods on beans in the child application context seem to get run without any bother, whilst 'PostDestroy' annotated methods in the parent application context do not get run unless I call the 'registerShutdownHook' method explicitly on that parent application context when I create it. Both application contexts use the '<context:annotation-config />' entry in the config. I have no problem with it, but it is not clear from the documentation (I have seen) if this is what is expected, and I just want to understand better. The full story seems to be that by default, when a job ends the 'doClose' method on the lower/child application context is the only 'doClose' method that runs. The 'doClose' methods on other application contexts’ up the hierarchy only seem to run if the shutdown hook has been explicitly registered on them.
I know certain activities are scoped to the containing application context, (componet-scan; annotation-config; aspectj-autoproxy etc), but was not aware of what I appear to be seeing here.
Is this as expected? If so, are there any other aspects which are confined to the lower level application context like this, unless explicitly activated on the parent application contexts’?


Reply With Quote