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. In this tutorial you will learn how to:
- Scaffold from a database table into an existing project
- Deploy a scaffolded application
1. Create a Web Project
Create a MyEclipse Web project named 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.
New web project
2. Scaffold from a Database Table
Scaffolding generates software components and configuration files required to implement the CRUD application.
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.
- Right-click CustomersApp, and select Spring Tools>Scaffold Spring CRUD Application This menu option was updated in MyEclipse 2017. For prior versions, click here. .
- Select the Database Schema option, which will scaffold from an existing database table in the MyEclipse Derby database. Click Next.
Selecting artifact types to use for scaffolding
- Select the MyEclipse Derby connection from the list of configured DB connections, and click Next.
Selecting the DB connection
- Select the CLASSICCARS schema, add the CUSTOMER table to the scaffolding list, and click Next.
Selecting the database table to use for scaffolding
- 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.
Database scaffolding options
- Specify the layers of the application to scaffold and the package names for each layer. All layers are enabled by default. Type
org.customerappas 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) is added to the end of the base package. Click Next.
Application layers and packages
- Select the Generate checkbox for Spring MVC to indicate which clients should be generated for the web layer, and click Next.
Selecting the Spring MVC web client
- Accept the default project configuration options, and click Next.
- Accept the default Spring Capabilities settings, and click Next.
Adding Spring capabilities
- Accept the default REST options, and click Next.
Accepting REST options default
- 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.
UI customization options
- Accept the default locations for generated files (source code, configuration files, JSP, etc…), and click Next.
Selecting target folders
- Accept the default runtime libraries and options, and click Next.
- Click Finish on the summary page.
3. Deploy the App
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 and click Finish.
Deploying the application
MyEclipse Tomcat 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 the generated application in operation. If you want to run the application in a separate browser, use the following URL:
The Spring MVC application can be used to list all customers, view customer details, edit customer details, delete customers and add new customers.
Customer app list
Customer app edit details
4. What’s Generated?
To ease your way into code generation, 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.