PDA

View Full Version : Spring startup / init


samspade
Jun 14th, 2007, 03:41 PM
What is the best way of calling a method or methods on init of the DispatchServlet? Extend it and override the init method, or is there a callback method Spring will call when the dispatcher servlet is first loaded ?

sami25
Jun 15th, 2007, 08:40 AM
What is the best way of calling a method or methods on init of the DispatchServlet? Extend it and override the init method, or is there a callback method Spring will call when the dispatcher servlet is first loaded ?

Hi, would like to know why you want to extend and override the init method of DispatcherServlet, I dont think so it is advisable,
rather use the interceptor HandlerInterceptorAdapter, and put your custom logic in the preHandle and postHandle appropriately.

ramin_farhanian
Jun 16th, 2007, 07:35 AM
Dear Samspade,
You didn't explain enough so that we can understand what exactly you need.
Spring has very good hooks everywhere. Around the request and response. After beans are visited by Spring but before they are initialized. After properties are set in a spring bean during initialization. When a bean is to be destroyed. If you let us know what you need, We try to help.

All The Best,
Ramin Farhanian

-FoX-
Jun 16th, 2007, 09:26 AM
You should never override the DispatcherServlet because it is designed following the "open for design, closed for extension" principle. There are plenty of ways to hook in the different lifecycles of the DispatcherServlet, so it is better to just use these 'hooks'.
It is also noteworthy that the Spring team once said the DispatcherServlet would become final in future releases... so be aware of this!