Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 4-6.FlightService Interface


public interface FlightService {


List<SpecialDeal> getSpecialDeals();

List<Flight> findFlights(SearchFlights search);

}


For the purposes of our example, we won’t concern ourselves with how this interface
is implemented. We want to show off Spring MVC, so in the meantime we will create a
DummyFlightServiceimplementation of FlightServicethat returns simple preset values.
In the real world, you would most likely create a Data Access Object (DAO) layer for deal-
ing with persistence. The service implementation would delegate to the DAOs, perform any
extra processing necessary, and return the results. The Spring Framework contains many
example projects that illustrate this architecture, and we recommend browsing through the
source code. For a more in-depth discussion of the implementation of a Spring Framework
application, consult the book Pro Spring by Rob Harrop and Jan Machacek (Apress, 2005).


ApplicationContext


The FlightServiceimplementation is defined inside this example’s main applicationContext.xml.
Normally, Dependency Injection would play a role in configuring your services, but for this
simple example it is enough to simply define the bean. Later the web components of the
application will be injected with this service, so it is important that the FlightServicebe
accessible as a Spring bean.
We are making a deliberate effort to separate our application beans from any web compo-
nents by creating separate ApplicationContexts. This ensures an obvious separation between
the different areas of the application.
For instance, in Listing 4-7, we are defining the DummyFlightServicebean in an
ApplicationContextthat is separate from any web components.


Listing 4-7.applicationContext.xml


<?xml version="1.0"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">



<bean id="flightService"
class="com.apress.expertspringmvc.flight.service.DummyFlightService" />


CHAPTER 4 ■JUMP INTO SPRING MVC 49
Free download pdf