Spring 3.0 tutorial – Part 1 (Setter DI )

This is a very simple Spring setter DI (depenendency injection tutorial). This assumes that you have gone through the “Setting up Java, Maven and Eclipse” tutorial. To recap:

1) Java, Maven, and eclipse are set up.
2) You have run the Maven archetype:generate command to create a skeleton structure.

3) import the project in eclipse.

4) You need to have a project structure as shown below with the relevant artifacts once gone through all the steps outlined below.


Step 1: pom.xml file with spring dependendencies. You can try using different (i.e. latest version of spring).

Spring Architecture

Spring Architecture

Step 2: Define the DAO layer Java interface and implementation for Course.

Step 3: Define the Service layer Java interface and implementation for Course.

Note: Note that “CoursDaoImpl” need to be injected via Spring into the “CourseServiceImpl”.

Step 4: The Spring context XML file that wires up dependencies. It defines the DAO and Service Java classes with “CoursDaoImpl” being injected into “CourseServiceImpl” via the setter injection.


Step 5: Finally, bootstrap the “courseApplicationContext.xml” via the App.java with the main method to execute this stand alone.


Java Interview FAQs

800+ Java Interview Q&As