Spring’s Dependency Injection & MVC

Sunday, March 29th, 2009

Below are slides from a presentation I gave to colleagues at Kiwiplan. The presentation covered two Spring Framework topics, the first being a brief introduction to Spring’s Dependency Injection Container. The second presentation was an introduction to Spring’s MVC (web) component, with a focus on the annotation style introduced in Spring 2.5. PDF versions are available for both Dependency Injection and MVC.

Tags: , , , , , , , ,

2 Comments to Spring’s Dependency Injection & MVC

Dave Birtwell
August 11, 2009

Hey Richard:

Any complete project source code to backup the MVC slides, especially with the filling of the JSP and form:select block? I’m attempting to use a SimpleFormController with @InitBinder and @ModelAttribute to pre-populate the selection dropdown, but the code doesn’t seem to get called and the dropdown stays empty.

Thanks,
Dave

Richard Paul
August 12, 2009

Hi Dave,

I’m not sure you are able to mix the Spring 2.0 (classic) style controllers with the Spring 2.5 annotations.

The SimpleFormController provides methods such as initBinder(HttpServletRequest request, ServletRequestDataBinder binder). While in Spring 2.5 you don’t extend any base classes, rather you simply mark up methods using the @InitBinder annotation.

Similarly @ModelAttribute exposes objects to the model, while in Spring 2.0 you would have used the referenceData method for this.

As for a working Spring 2.5 MVC example, the Spring download with docs includes sample applications. Check out the petclinic example in http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-2.5.6.SEC01-with-docs.zip

Hope that helps,
Richard.

Leave a comment