How spring flow


  • Web.xml file is Written .will be load first and inside web.xml file we have one default file  will we load 
  • Inside at least one servlet should be .
  • Whatever the bean we are writing inside this file will be loaded at server startup or first User Request. i.e Connection beans ,database related beans,tx beans ..etc.
  • For Spring Mvc dispatcherServlet have used -called front controller its take care all the user request and further process .How http request response will be process all stuff will handled by DS Servlet .
Flow:

Step 1: first user request will be take by DispatcherServlet.
Step 2DS  will call and take the help of HandlerMapping and get to know the Controller class .
Step 3: And then controller will process the request by executing appropriate methods and return back the View using ModelAndView
Step 4: Actual view will populated and
Step 5: Finally DS will pass the Model object to the View page to display the View with result on UI.

Note: If we are going for annotation based then some setting should be specified .
  • in web.xml <mvc:annotation-driven /> tag should be.
  • <context:component-scan> tag.

Spring Mvc Annotation:
@ContrllerAdvice -this annotation is use to handled global level functionality if we miss out any exception logic at locally in out controller.
-To write this a Seperate class is written with @ContrllerAdvice
-If there is no locally defined @ExceptionHandler, @modelAttribute, the globally defined class annotated with @ControllerAdvice is served. 
-To use @ControllerAdvice, we should use @EnableWebMvc annotation in our Java config file. 
Note:this came in Spring 3.2. I.e
Suppose i have a Controller method with @RequestMapping and inside i throw FileNotFoundException and this exception is not written inside controller class @Exceptionhandler .then auto @ControllerAdvice class will come in picture & take care by below.
 @ControllerAdvice(basePackages={"com.sam"})
Public Class A{
//

@ExceptionHandler(FileNotFoundException.class)
ModelAndview mineError(Exception ex){
//error msg
return view;
}

}

Comments

Popular posts from this blog

Angular 2 & 2+

Ajax calling to controller