View Full Version : Doubt in initApplicationContext() method
rajeshrathod
Sep 10th, 2007, 04:28 AM
Hello friends,
I am new in Spring framework. I am making one small application using AbstractController. When i was reading about AbstractController i came across initApplicationContext() method. I tried to search lot of thing but i am not able to digest the concept of this method.
So here can anybody Please tell me the use of this method and how to call it into the implementation class.
Thanks in advance.
infinity2heaven
Sep 10th, 2007, 02:41 PM
First of all you most probably will never need to use AbstractController directly. If you're "new" to Spring, I'd recommend reading SimpleFormController and a sample code on the same. If you still want to use AbstractController, then all you need to do is override handleRequestInternal() and return a ModelAndView.
initApplicationContext is provided in ApplicationObjectSupport (http://www.springframework.org/docs/api/org/springframework/context/support/ApplicationObjectSupport.html), which is being extended by WebContentGenerator (extended by AbstractController). None of them override this template method (default is no implementation) and I don't see why you would like to override the same in your application code.
/**
* Subclasses can override this for custom initialization behavior.
* Gets called by <code>setApplicationContext</code> after setting the context instance.
* <p>Note: Does </i>not</i> get called on reinitialization of the context
* but rather just on first initialization of this object's context reference.
* @throws ApplicationContextException in case of initialization errors
* @throws BeansException if thrown by ApplicationContext methods
* @see #setApplicationContext
*/
protected void initApplicationContext() throws BeansException {
}
If you're still interested how you could use the same, I'd suggest read the code of SimpleUrlHandlerMapping, it ultimately extends ApplicationObjectSupport (http://www.springframework.org/docs/api/org/springframework/context/support/ApplicationObjectSupport.html) class and does override initApplicationContext. In this case, it registers all the handlers for the given url path
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.