Scaffolding a Spring MVC Application
This tutorial walks you through producing a ready-to-run Spring MVC customer application that implements the CRUD application pattern for a domain model. Scaffolding with Spring MVC requires a MyEclipse Spring or Bling subscription. In this tutorial you will learn how to:
- Scaffold from a database table into an existing project
- Deploy a scaffolded application
Duration Time: 30 Minutes
Don't have MyEclipse? Download Now
Create a MyEclipse Web project called CustomersApp.
Note: If you get a popup regarding the project compiler compliance level not matching the workspace default, specify that you want to use a custom setting for the project by clicking Yes.
Scaffolding generates software components and configuration files required to implement the CRUD application.
- Right-click CustomersApp, and select MyEclipse>Scaffold Spring CRUD Application.
- Select the Database Schema option, which will scaffold from an existing database table in the MyEclipse Derby database. Click Next.
- Select the MyEclipse Derby connection from the list of configured DB connections, and click Next.
- Select the CLASSICCARS schema, add the CUSTOMER table to the scaffolding list, and click Next.
- Accept the selected Java object as the parent object, and click Next.
This page also lets you override the derived name of the Java object created from the database table. Java object names are derived automatically from table names, but the name can be overridden by double-clicking the name and typing a new name.
- Specify which layers of the application
should be scaffolded and which package names should be used for each
layer. All the layers are enabled by default. Type org.customerapp as the base package. The package
names for the layers are derived automatically from
the base package. A sub-package (i.e., web, service, DAO, and domain)
are added to the end of the base package. Click Next.
- Select the Generate checkbox for Spring MVC to indicate which clients should be generated for the web layer, and click Next.
- Accept the default project configuration options, and click Next.
- Accept the default Spring Capabilities settings, and click Next.
- Accept the default REST options, and click Next.
- Accept the defaults on the Customize UI page, and click Next.
Note: The field names are derived automatically from the column names of the selected database tables, but the field name can be overridden by double-clicking the name and typing a new name.
- Accept the default locations for generated files (source code, configuration files, JSP, etc...), and click Next.
- Accept the default runtime libraries and options, and click Next.
- Click Finish on the summary page.
Note: If you want to use the Spring DSL, then you need enable the project for Spring DSL support prior to scaffolding. See Enable Spring DSL for more information.
The next step is to see the application in operation by deploying it to Tomcat. The running application can be used for validating the generated Spring MVC components and observing the integration with the other components of the application.
- Right-click CustomersApp, and select Run As>MyEclipse Server Application. Select the MyEclipse Tomcat application server.
MyEclipse Tomcat starts opens the application. The first page is a dashboard for accessing all scaffolded web clients. Because this tutorial only scaffolded a single database table for Spring MVC, the only option under Spring MVC is View Customers.
- Click the View Customers button to see generated application in operation. If you want to run the application in a separate browser, use the following URL: http://localhost:8080/CustomersApp/.
The Spring MVC application can be used to list all customers, view customer details, edit customer details, delete customers and add new customers.
To ease your way into code generation with ME4S, this tutorial involved scaffolding from only a single database table. Therefore, only the software components for managing a single entity were generated, and there were no entity relationships. When you start generating for multiple entities, potentially with entity relationships, there are many more software components generated than were generated with this tutorial. Even though there's a lot more code, it is grouped and organized as shown in the following images.