Annotation-based Spring Portlet MVC Lifecycle

Jan 17 2009

Jared Richardson spoke at a Richmond Java Users Group meeting I attended last week; his topic was about investing in yourself and your career - what he called career 2.0. At one point during the presentation, he noted that “if you can’t draw something, you don’t understand it”, which motivated me to finish a blog post I started a while back about Spring Portlet MVC.

I gave a presentation at CapTech’s Feed Your Brain series about using Spring Portlet MVC’s annotation-driven development style, and I wanted to diagram how the lifecycle works under the covers.

Annotation Driven Portlet Development with Spring View more presentations from Andy Pemberton.

The following diagram never made it into the presentation so I wanted to post it here.

Sorry if the graphic doesn’t blow you away; I have an older version of OmniGraffle - but want to get one of these.

So, in short the graphic depicts:

  1. like most implementations of the Front Controller pattern, the DispatcherPortlet sits in front of all PortletRequests
  2. if a DefaultAnnotationHandlerMapping is set as the default HandlerMapping implementation in your Portlet’s Spring application context, the DispatcherPortlet will use it to find a @Controller
  3. the DefaultAnnotationHandlerMapping itself searches your application context for the best matching class annotated as a @Controller
  4. the DefaultAnnotationHandlerMapping then passes control back to the DispatcherServlet, which then needs a AnnotationMethodHandlerAdapter to determine which method to call on your controller
  5. the AnnotationMethodHandlerAdapter then checks for methods annotated with @RequestMapping and, again, finds the “best match” method to handle the PortletRequest
  6. the request is served, and control is passed back to the DispatcherPortlet - voila!

Hope this is helpful to those looking to use Spring Portlet MVC’s nifty annotation model.

About the Author

Andy Pemberton's picture

Andy Pemberton is a Sun Certified Enterprise Architect and Lead Consultant. Andy is an open source enthusiast with a depth of experience in JavaEE and Portal environments.

Disclaimer

The words and opinions expressed here are those of each article's respective author, and do not necessarily represent the views of CapTech Ventures.