The entire app must have a clear start/stop lifecycle correctly implemented. Static registrations in non-webapp services must be removed, and/or those services must use weak references.
The list is quite long. (Source - I have done my fair share of middleware and know tomcat source quite well)