Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

REST based web applications with Spring 3

14,849 views

Published on

Slides of the talk I gave at Java User Group Frankfurt, March 31st 2010.

Published in: Technology
  • Be the first to comment

REST based web applications with Spring 3

  1. 1. REST based web applications with Spring 3 Oliver Gierke - Senior Consultant © 2010 SpringSource, A division of VMware. All rights reserved
  2. 2. Agenda  Intro  What is REST all about?  Recap: @Controller  What‘s new in Spring MVC 3.0?  What‘s beyond Spring MVC  Demo 2
  3. 3. About  Oliver Gierke - Senior Consultant Hi! My name is...  OpenSource enthusiast  (OR)Persistence, Web, Integration  ogierke@vmware.com  http://www.olivergierke.de / olivergierke 3
  4. 4. SpringSource - a division of VMware  Spring Framework • exhaustive ecosystem  Roo  Groovy / Grails  Tomcat / tc Server / Hyperic 4
  5. 5. REST 5
  6. 6. The architecture of the web 6
  7. 7. Identifiers Verbs Resources Hypermedia Representations 7
  8. 8. Spring MVC 8
  9. 9. Spring MVC Model View Controller 9
  10. 10. Recap: Spring MVC 2.5 10
  11. 11. @Controller @Controller @RequestMapping(„/addresses“) public class AddressController { @RequestMapping(value=“/address“, method = GET) public String showAddress( @RequestParam Long id, Model model) {…} } 11
  12. 12. Strongly typed methods @RequestMapping(value=“/address“, method = GET) public String showAddress( @RequestParam Long id, Model model) {…} Strongly typed Other special View name request parameter types 12
  13. 13. What‘s new in Spring MVC 3.0  @PathVariable  Content negotiation  ResponseBody / RequestBody / ResponseStatus  Declarative validation (JSR-303) 13
  14. 14. @PathVariable @RequestMapping(value=“/addresses/{id}“, method = GET) public String showAddress( @PathVariable Long id, Model model) {…} 14
  15. 15. Content negotiation http://myapp.com/addresses/1.xml http://myapp.com/addresses/1.json http://myapp.com/addresses/1.html Accept: application/xml Accept: application/json Accept: application/html 15
  16. 16. @ResposeBody @RequestMapping(value=“/addresses/{id}“, method = GET) @ResponseBody public Address showAddress( @PathVariable Long id, Model model) {…} 16
  17. 17. @ResponseStatus @ResponseStatus(NOT_FOUND) public class MyException extends RuntimeException {…} 17
  18. 18. @ResponseStatus @RequestMapping(value=“/addresses/{id}“, method = GET) public String showAddress( @PathVariable Long id, Model model) { if (id == null) throw new MyException(); … } 18
  19. 19. @RequestBody @RequestMapping(value=“/addresses“, method = POST) @ResponseStatus(CREATED) public void createAddress( @RequestBody Address address) {…} 19
  20. 20. Declarative Validation @RequestMapping(value=“/addresses“, method = POST) @ResponseStatus(CREATED) public void createAddress( @RequestBody @Valid Address address) {…} 20
  21. 21. What‘s new in Spring MVC 3.0  New data binding and type conversion service  Object-XML-Mapping  HiddenHttpMethodFilter  XML namespace 21
  22. 22. Demo 22
  23. 23. Where do we go from here? 23
  24. 24. Spring WebServices Spring WebFlow Spring Integration Spring Ecosystem Spring Batch Spring Roo Spring Security 24
  25. 25. Demo 25
  26. 26. Questions 26
  27. 27. Resources  Sample: http://github.com/olivergierke/spring-rest  Petcare: http://src.springsource.org/svn/spring-samples/petcare/trunk  Photos: http://www.sxc.hu/ 27

×