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

Start Tutorial Now

Don't have MyEclipse? Download Now

1. Create a Web Project

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.

New web project

2. Scaffold from a Database Table

Scaffolding generates software components and  configuration files required to implement the CRUD application.

  1. Right-click CustomersApp, and select MyEclipse>Scaffold Spring CRUD Application.

    Scaffolding the application
  2. Select the Database Schema option, which will scaffold from an existing database table in the MyEclipse Derby database. Click Next.

    Selecting artifact types from which to scaffold
  3. Select the MyEclipse Derby connection from the list of configured DB connections, and click Next.

    Selecting the DB connection
  4. Select the CLASSICCARS schema, add the CUSTOMER table to the scaffolding list, and click Next.

    Selecting database table from which to scaffold
  5. 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
  6. 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.

    Application layers and packages
  7. 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
  8. Accept the default project configuration options, and click Next.

    Configuration options
  9. Accept the default Spring Capabilities settings, and click Next.

    Adding Spring capabilities
  10. Accept the default REST options, and click Next.

    Accepting REST options default
  11. 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
  12. Accept the default locations for generated files (source code, configuration files, JSP, etc...), and click Next.

    Selecting target folders
  13. Accept the default runtime libraries and options, and click Next.

    Runtime dependencies
  14. Click Finish on the summary page.

    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.

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.

  1. Right-click CustomersApp, and select Run As>MyEclipse Server Application. Select the MyEclipse Tomcat application server.

    Deploying the applicationMyEclipse 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.
  2. 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.

Customer app list
Customer app edit details

4. What's Generated?

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.

Generated scaffolding