In this session you will learn:
1. Spring framework
2. Inversion of Control
3. Dependency Injection – Two types
4. Defining beans using XML
5. Inheriting beans
6. Auto-wiring
7. Annotations based on a configuration
8. Java-based configuration
9. Spring AOP
2. Page 1Classification: Restricted
Review
• Spring framework
• Inversion of Control
• Dependency Injection – Two types
• Defining beans using XML
• Inheriting beans
• Auto-wiring
• Annotations based configuration
• Java based configuration
• Spring AOP
6. Page 5Classification: Restricted
MVC…
• What is MVC pattern? Review…
• The Model encapsulates the application data and in general they will
consist of POJO.
• The View is responsible for rendering the model data and in general it
generates HTML output that the client's browser can interpret.
• The Controller is responsible for processing user requests and building
appropriate model and passes it to the view for rendering.
7. Page 6Classification: Restricted
Spring MVC
• Spring MVC tutorial provides an elegant solution to use MVC in Spring
framework by the help of DispatcherServlet.
• In Spring Web MVC, DispatcherServlet class works as the front controller. It
is responsible to manage the flow of the Spring MVC application.
• The @Controller annotation is used to mark the class as the controller in
Spring 3.
• The @RequestMapping annotation is used to map the request url. It is
applied on the method.
8. Page 7Classification: Restricted
Advantages of Spring 3.0 MVC
• Supports RESTful URLs.
• Annotation based configuration.
• Supports to plug with other MVC frameworks like Struts etc.
• Flexible in supporting different view types like JSP, velocity, XML, PDF etc.,
16. Page 15Classification: Restricted
@RequestMapping with HTTP Method
@RequestMapping(value="/student", method=RequestMethod.POST)
@ResponseBody
public String method2(){
return “some string";
}
@RequestMapping(value="/student2",
method={RequestMethod.POST,RequestMethod.GET})
@ResponseBody
public String method3(){
return “some string";
}
17. Page 16Classification: Restricted
@RequestMapping with Headers
@RequestMapping(value="/student", headers="name=Pawan")
@ResponseBody
public String method4(){
return “something";
}
@RequestMapping(value="/method5", headers={"name=Pawan", "id=1"})
@ResponseBody
public String method5(){
return “some return value";
}
18. Page 17Classification: Restricted
@RequestMapping with @PathVariable
@RequestMapping(value="/student/{id}")
@ResponseBody
public String method7(@PathVariable("id") int id){
return “the value with id="+id;
}
19. Page 18Classification: Restricted
@RequestMapping with @RequestParam for URL parameters
@RequestMapping(value="/student") //e.g.
http://....appname/student?id=111
@ResponseBody
public String method9(@RequestParam("id") int id){
return “student with id= "+id;
}