Chapter 8. Annotation-driven development with Spring

 

This chapter covers

  • Spring Portlet MVC annotations
  • Dependency injection using JSR 330 and JSR 250
  • Validation using Spring Validation API and JSR 303
  • Using Spring’s form tag library
  • Localization and file upload support
  • Unit testing with Spring’s TestContext framework

In the previous chapter, you created Spring controllers and provided a HandlerMapping bean definition in the web application context XML file to map portlet requests to appropriate controllers. But wouldn’t it be easier if you could specify which portlet request is handled by a controller in the controller class itself? In this chapter, we’ll expand on the core concepts covered in the previous chapter and see how Spring’s annotation support helps you reduce the amount of configuration information in the application context XML files and simplify application development.

The annotations covered in this chapter span multiple aspects of portlet development using Spring, from writing request handlers, to dependency injection, to validation and testing. This chapter demonstrates these aspects in the development of the Book Catalog portlet, to show how Spring simplifies portlet development using annotations.

8.1. An overview of annotations

8.2. Developing the Book Catalog portlet using annotations

8.3. Spring Portlet MVC annotations

8.4. Configuring beans that provide annotation support

8.5. Validating forms using Spring and JSR 303

8.6. Spring’s form tag library

8.7. Unit testing with mock objects and TestContext

8.8. Localizing content, uploading files, and adding CSS and JavaScript

8.9. Summary