Learn Java for Web Development

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
























You can choose any name you like for beans.xml. You have to make sure that this file is available in
CLASSPATH and use the same name in the main application while creating the application context, as
shown in the VehicleApp.java file. Figure 5-4 shows the directory structure of the application.


Figure 5-4. Directory structure


Addressing Cross-Cutting Concerns Using AOP

A separation of concerns is achieved in Spring by means of aspect-oriented programming (AOP).
AOP encapsulates the cross-cutting concerns in separate, reusable components called aspects
and adds them to the application. This process is called weaving. This results in the cohesive
components that concentrate on the business functions and are totally unaware of system services
such as logging, security, transaction, and so on. To understand how aspects can be applied in
Spring, you will now create a simple BookService that retrieves a list of all books, adding a basic
logging aspect to the BookService. The code for this application is available in a downloadable
archive on the Apress web site. Listing 5-18 illustrates the BookService.

Free download pdf