Learn Java for Web Development

(Tina Meador) #1
CHAPTER 5: Building Java Web Applications with Spring Web MVC 215

To add the Spring Framework to your project, right-click your project and select Build Path ➤ Configure
Build Path to display the Java Build Path window as illustrated in Figure 5-3. Now add the external
JARs that you downloaded in your file system from the Apress website.


Figure 5-3. Adding external JARs


Now let’s create actual source files under the looselyCoupledApplication project. First we need to
create a package called com.apress.decoupled. To do this, right-click src in the Package Explorer
section, select New ➤ Package, and create the package com.apress.decoupled. Then create
Vehicle.java, Car.java, and Bike.java, which is the code illustrated in Listings 5-10, 5-11,
and 5-12, under the com.apress.decoupled package.


Then create the class VehicleService as illustrated in Listing 5-15.


Listing 5-15. Loosely Coupled VehicleService



  1. package com.apress.decoupled;



  2. public class VehicleService {



  3. private Vehicle vehicle;



  4. public void setVehicle(Vehicle vehicle) {

  5. this.vehicle = vehicle;

  6. }

Free download pdf