Spring Bean Life Cycle
- Default constructor will be called.
- All properties setter methods will be called.
- If class implements BeanNameAware then setBeanName method will be called.
- If class implements BeanFactoryAware then setBeanFactory method will be called.
- If class implements ApplicationContextAware then setApplicationContext method will be called.
- If class implements BeanPostProcessor then its postProcessBeforeInitialization will be called.
- If class implements InitializingBean then afterPropertiesSet method will be called.
- If class has custom init method defined then it will be called.
- If class implements BeanPostProcessor then its postProcessAfterInitializationwill be called.
- If class implements DisposableBean then destroy method will be called.
- If class has custom destroy method defined then it will be called.
1. Dipatcher Servlet which is also know as front controller of Spring application handles all the request mapped to it in web.xml and ask for appropriate controller from Handler Mapping
2. Handler Mapping is a configuration for url and controller mapping. It look for controller:
Popular Implentations of HandlerMapping:
BeanNameUrlHandlerMapping - This is a default spring handler mapping. Name of bean considered as URL.
Popular Implentations of HandlerMapping:
BeanNameUrlHandlerMapping - This is a default spring handler mapping. Name of bean considered as URL.
<bean name="/welcome.htm" class="com.help4j.controller.WelcomeController" />
SimpleUrlHandlerMapping - Map with key value pair of URL and controller bean name.
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">welcomeController</prop>
</props>
</property>
</bean>
<bean id="welcomeController" class="com.help4j.controller.WelcomeController" />
DefaultAnnotationHandlerMapping - Annotation based @RequestMapping at class and method level.
WelcomeController.java
package com.help4j.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/welcome")
public class WelcomeController{
@RequestMapping(method = RequestMethod.GET)
public ModelAndView helloWorld(){
ModelAndView model = new ModelAndView("WelcomePage");
model.addObject("msg", "hello world");
return model;
}
}
3. Controller calls service layer to execute business logic and retrurn ModelAndView, which is wrapper for model object and view name.
Popular Controller Types:
Popular Controller Types:
AbstractController
AbstractCommandController
SimpleFormController
4. View Resolver look for appropriate view JSP/HTML based on view name and return to user.
Popular Implentations of ViewResolver:
Popular Implentations of ViewResolver:
InternalResourceViewResolver
No comments:
Post a Comment