This tutorial will detail how to insert services and components (Dependency Injection) into a Spring 3 Web MVC Netbeans application.

The process used is Dependency Injection (DI) or Inverse of Control (IoC) whereby Spring will instantiate (or inject) certain components at runtime rather than at having them initiated at compile time. This provides a highly decoupled design which facilitates ‘change’ more easily. Importantly, it also makes comprehensive Unit Testing (with Mock Objects) much easier to achieve. IoC is a conventional design pattern.

This tutorial is quite comprehensive in that it will simulate CRUD operations on ‘Person’ objects. For simplicity, it does not used a database, data will be put stored in the ‘HttpSession’ object instead.

6-Nov-2014 –> Please note that a new blog now exists for Spring 4 Web MVC using Maven and Netbeans with Java configuration (no XML at all) here – John

This tutorial will simply detail one correct way to create a simple Spring 3 web application using Netbeans.

Note: The Spring plugin for Netbeans (that is being distributed with Netbeans 7.7.1 and previous) is actually designed for Spring 2 and is therefore somewhat misleading. This tutorial overcomes that giving you the correct way to generate a Spring 3 web project.

A fully working Netbeans project is available for download at the bottom of the page.