CHAPTER 5: Building Java Web Applications with Spring Web MVC 221
- BookService bookService = (BookService)context.getBean("bookService");
- bookService.getAllBooks();
- }
- }
Figure 5-5 illustrates the directory structure of this application.
Figure 5-5. Directory structure
Thus, Spring AOP can be employed to provide services such as transactions and security
declaratively without tangling up your code that, in first place, should remain concerned only with its
business functions.
Removing Boilerplate Code Using Templates
In Chapter 1 we built the data access layer of the bookstore application and used pure JDBC in the
BookDAOImpl to connect to the database. In this section, you will see how the Spring Framework, by
means of Spring’s JDBCTemplate, transforms the BookDAOImpl, eliminating the boilerplate code that
results from using pure JDBC to obtain a connection to a data store, and cleans up resources. The
code for this application is available in the downloadable archive on the Apress web site. Listing 5-23
illustrates the BookService.