After the field properties are generated, the next step is to configure Spring Data JPA repository
abstraction for the Contact class. Enter the following command into the Roo prompt:
repository jpa --interface ~.repository.ContactRepository --entity ~.domain.Contact
The previous command instructs Roo to generate the JPA repository interface that uses Spring Data
JPA. At this point, the persistence layer is basically complete.
Set Up the Service Layer
Starting with version 1.2.0, Roo added support for generating service-layer classes. To see this in action,
let's create the ContactService interface like we did in previous chapters. To do this, enter the following
command at the Roo prompt:
service --interface ~.service.ContactService --entity ~.domain.Contact
The service command is used to instruct Roo to create the ContactService interface, which will be
used to manipulate the Contact entity class. Upon completion, in the Package Explorer, you will see that
besides the interface class, Roo also generates the implementation class ContactServiceImpl. In
addition, if you take a look at the ITD ContactServiceImpl_Roo_Service.aj file that Roo generates, the
repository interface (ContactRepository) is autowired into the service class automatically.
At this point, a backend for the Contact entity class with basic CRUD operations support is created.
Set Up the Presentation Layer
In Spring Roo, generating a web application with Spring MVC is extremely easy. First we need to instruct
Roo to set up Spring MVC for the application. Enter the following command at the Roo prompt:
web mvc setup
If you look at the Package Explorer now, you will see that Roo generated the web environment folder
structure, the web deployment descriptor (web.xml), the DispatcherServlet WebApplicationContext
configuration file (webmvc-config.xml), and so on.
The next step is to generate the controller class and view files for the Contact entity class. To do this,
enter the following command at the Roo prompt:
web mvc all --package ~.web.controller
The command simply instructs Roo to generate scaffold Spring MVC controllers for all entities in
the project without an existing controller class. Roo with then generate the controller class for the
Contact entity, as well as the JSPX view files for maintaining contact information.
Now a basic application is generated, and after building and deploying to the tc Server in STS, start
the server, and enter the URL http://localhost:8080/ch20-roo in the browser. The application will be
displayed, as shown in Figure 20-18.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home