So while I was trying to scrape a Groovy mess off of my heel I found a real gem in the Pro Spring book.
For those who want to read it themselves you can find what I read on pages 95-110 in the Yellow and black book called Pro Spring.
The Spring Framework provides two interfaces that will make it possible to run code after creation and/or before destruction.
To get a call after creation make your bean implement InitializingBean. Then you will need to implement the method public void afterPropertiesSet() throws Exception. This method will be called after the bean is instantiated and the property injection has been done.
To get a call before bean destruction make your bean implement DisposableBean. Then you will need to implement the method public void destroy(). This method will be called before the bean is destroyed so you can clean stuff up.
Very Important Note When I was trying this out I found that one of our apps did not ever call the destroy method. I poked around a little and found that the contextDestroyed() method in the ContextListener was not calling the super.contextDestroyed(). I suspect that thing may also be a problem for other applications.
This app had not been closing cleanly for a long time and when this bug in ContextListener was fixed it started closing cleanly. Awesome! It also called the destroy method on my bean.



Can you give me some examples of what I would do in these calls? Did you happen to check if the non-call is an issue in appfuse, since that would probably mean in a bunch of places.
Sure,
Instead of adding setup code to the ContextListener class for the db or caches or logging etc. That code could be placed in the Manager that it is related to.
I just used it for set up of the telnetd for a project I’ve been doing. More on that soon.
So I looked at a couple AppFuse projects and found that this is NOT a problem for them. We have not overridden the
contextDestroyed()method.In AppFuse the pertinent class is in the web module in the listener package and is called
StartupListener. If you look in one of these classes you will see that there is A LOT of code in thecontextInitialize()method. (Large method code smell) and a lot of it probably could be put into theafterPropertiesSet()method of some Manager or other.