MyEclipse for Spring 10.0: Spring 3.0 MVC Scaffolding

Posted: March 2, 2012 in Java Posts
Tags: , , , , ,

1. Introduction

One of the goals of MyEclipse for Spring (ME4S) is to help developers write less code from scratch and use code generation more broadly, and ME4S offers the richest set of code generation options available anywhere. ME4S can generate software components for Spring MVC, Spring Web Flow, Spring Security, REST, JAX-WS, Adobe Flex, Google Web Toolkit (GWT), JPA, DAO and JSF 2.0/Primefaces. As an alternative to writing software components from scratch, ME4S helps developers generate software components that are specific to their project. In many cases the software components may be used as-is, or they may be used as a starting point for further development. Furthermore the developer can edit the ME4S templates to further customize how the software components are generated.

Scaffolding refers to the superset of ME4S’s broad code generation functions, from generating a specific set of requested software components to generating fully implemented ready-to-run applications. Besides the obvious benefits of reducing application development effort and sparing developers from some of the chores of development, scaffolding is also frequently used for rapidly developing functional prototypes, learning new technologies, and application modernization projects. The ability to quickly generate a full application is very beneficial to prototyping because you can iterate on a domain model and regenerate a functional prototype in minutes. The prototype can be used with business analysts as a tool for elaborating requirements and as the starting point for development. ME4S helps many developers learn new technologies by generating contextual reference projects, which are personalized projects that are based on their own data model. This is a considerably better approach than hunting for sample projects that are often incomplete, don’t follow modern best practices, and are based on trivial data models. ME4S can also be used to jumpstart an application modernization effort by leveraging application artifacts from the current system for generating a significant portion of the application components for the new system.

The objective of this tutorial is to walk you through the generation of software components for Spring MVC, which is a web framework from the creators of the Spring framework. In addition to generating the Spring MVC software components, this tutorial will also generate the software components for the service, domain, and data access layers. This will result in a fully implemented ready-to-run Spring MVC application that can be immediately used for validating and testing the generated Spring MVC components, and it will also serve a reference implementation for how the generated Spring MVC components integrate with the other components of an application.

Figure 1. Application Layers – Spring MVC

 

Application Architecture:

  • Web Layer – Spring MVC (@Controller)
  • Service Layer – Spring (@Service)
  • Domain Layer – JPA (@Entity)
  • Data Access Layer – Spring (@Repository)

Spring MVC – Annotation-based Programming Model

Spring MVC supports multiple approaches for implementing the web layer, and Spring 2.5 added support for an annotation-based programming model. The annotation-based approach has quickly become the predominant way of using Spring MVC, and it’s generally regarded as the best practice in Spring MVC development. The scaffolding functions of MyEclipse for Spring will generate the web layer using the annotation-based programming model.

What about other web technologies?

This tutorial is focused on Spring MVC, but the scaffolding wizard can also generate the web layer implementation for Spring Web Flow, JavaServer Faces (JSF 2.0), Adobe Flex, Google Web Toolkit (GWT) and iPhone.

Figure 2. MyEclipse for Spring CRUD Scaffolding

MyEclipse for Spring uses the Create-Read-Update-Delete (CRUD) application pattern for generating applications that allows the end-user to manage application data. While CRUD isn’t the only application pattern, it’s a fairly typical application pattern. While not all web applications are satisfied solely by the CRUD application pattern, developers find that the resulting generated application artifacts lend themselves to being easily re-used, customized and extended. CRUD applications are tied to an application domain model that is used as the input into the scaffolding engine. The domain model can exist in many forms, and the MyEclipse for Spring scaffolding functionality supports the use of Java beans, JPA entities, or database tables as inputs.

2. Goal

This tutorial is going to walk you through producing a ready-to-run Spring MVC application that implements the CRUD application pattern for a domain model.

  • Domain model: CUSTOMERS table from the MyEclipse Derby database.
  • Target Container: MyEclipse Tomcat
  • Target Database: MyEclipse Derby

MyEclipse for Spring will be used to generate the entire Spring 3.0 application within a matter of minutes that includes:

  • A JPA entity corresponding to domain model (CUSTOMERS)
  • A DAO for managing the JPA entity,
  • Finder methods (JPA named queries) in the DAO based on domain model fields,
  • A Service with fully implemented CRUD operations for managing domain model,
  • A Controller with fully implemented request handlers for supporting web application,
  • All the necessary Spring annotations and configuration files for a Spring MVC app,
  • CRUD JSP pages using Spring Form tag library and JSTL
  • Layout managed user interface using Sitemesh,
  • Client-side validation implemented Spring JS with DOJO,
  • CSS for UI styling
  • JUnits for every Service and Controller,
  • SpringSource certified code and configuration files,
  • Generated code that follows Spring Recipes,

3. Prerequisites

The prerequisites needed to complete this tutorial are:

4. Create Web Project

  1. Create a MyEclipse Web Project (or Eclipse Dynamic Web Project) called CustomersApp.
    Figure 3. New Web Project

    Incompatible Compiler Compliance Level

    If you get a popup dialog regarding the project compiler compliance level not matching the workspace default, specify that you want to use a custom setting for the project [click the Yes button].

5. Scaffold from Database Tables

It’s now time to generate all the software components and configuration files required to implement the CRUD application.

  1. Right-click on the CustomersApp project, and choose MyEclipse > Scaffold Spring CRUD application…
    Figure 4. Scaffolding Wizard

  2. The first step is to select the type of artifact you want to scaffold from. As mentioned in the introduction there are a variety of possible inputs into scaffolding. For this tutorial we’re going to scaffold from a pre-existing database table that comes with the MyEclipse Derby database. Choose the Database Schema option on the Select Artifact Type(s) panel. Click the Next button.
    Figure 5. Select Artifact Type(s)

  3. The next step is to select the DB connection for accessing the MyEclipse Derby database. This panel will show you all configured DB connections in the MyEclipse workspace, and you must select the MyEclipse Derby connection, which is a preconfigured DB connection in MyEclipse. Click the Next button.
    Figure 6. Specify Persistence Connection Properties

  4. The next step is to specify which database table(s) to scaffold an application from. Start by selecting the desired schema, and the select the database table(s) that should be used for scaffolding. When the CLASSICCARS schema is selected, the tables list will be populated with a list of tables. The CUSTOMER table should be added to the scaffolding list. Click the Next button.
    Figure 7. Select Database Tables

  5. The next panel will prompt you to select parent objects, and this panel also lets you override the derived name of the Java Object that will be created from the database table. Since we’re only scaffolding from a single database table, the Customer Java object must be the parent. For this tutorial there’s nothing that needs to be changed on this panel. Just click the Next button.
    Figure 8. Database Scaffolding Options

    Overriding derived Java object names

    Java Object names are automatically derived from table names, but the name can be overridden by double-clicking on the name and typing a new name.

  6. The next step is to 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. Enter org.customerapp as the base package. The package names for the different layers will be automatically derived from the base package. A sub-package (i.e. web, service, DAO, and domain) will be added to the end of the base package.
    Figure 9. Application Layers and Packages

  7. The next step is to specify which web clients should be generated for the web layer. As you can see, there are a variety of different web clients available, including Spring MVC, Spring Web Flow, Adobe Flex, GWT, and iPhone. This tutorial is focused on Spring MVC, so click on the Generate checkbox for Spring MVC.
    Figure 10. Select Web Client

  8. The next step is an optional step to specify the REST scaffolding options. Since REST scaffolding is beyond the scope of this tutorial, we’ll just skip to the next step of the wizard.
    Figure 11. REST options

  9. The next step is in an optional step to customize the UI. For this tutorial we’ll go with the defaults.
    Figure 12. Customize UI

    Overriding field names for user interface

    The field names are automatically derived from the column names of the selected database tables, but the field name can be overridden by double-clicking on the name and typing a new name.

  10. The next step is to specify where the application (source code, configuration files, JSP, etc…) should be generated to in the current project and a few additional scaffolding options. For this panel the defaults are fine. Click the Next button.
    Figure 13. Select Target Folders

  11. The final configuration step is to specify the libraries that should be added to the current project, how they should be added (classpath containers or copied into project), and the version of Spring MVC to use. For this panel the defaults are fine. Click the Next button.
    Figure 14. Runtime Dependencies

  12. The final panel will give you a summary of everything that will be generated for you. Click the Finish button to scaffold the application from the information you provided in the wizard.
    Figure 15. Summary

That’s it. Once the wizard is complete you have a ready-to-run Spring MVC application that implements the CRUD application pattern for the domain model (CUSTOMERS DB table).

Scaffold Spring DSL

If you want to use the Spring DSL, then you will need enable the project for Spring DSL support prior to scaffolding. See Enable Spring DSL in the reference guide for more info.

6. 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. To deploy the application, right-click on the CustomersApp project and select Run As –> MyEclipse Server Application.
    Figure 16. Run As –> MyEclipse Server Application

  2. MyEclipse Tomcat will start up. The first page will be a dashboard for accessing all scaffolded web clients. Since this tutorial only scaffolded a single database table for Spring MVC, the only option under Spring MVC is View Customers. Click on it to see generated Spring MVC application in operation.

    Run in a separate web browser?

    If you want to run the Spring MVC application in a separate browser, use the following URL: http://localhost/CustomersApp/

    Figure 17. Dashboard

  3. The Spring MVC application can be used to (a) list all customers, (b) view customer details, (c) edit customer details, (d) delete customers and (e) add new customers. The following screen shots show some of the views.
    Figure 18. CustomerApp – List

    Figure 19. CustomerApp – Edit Details

7. What’s generated?

The scaffolded application is compromised of many integrated software components, and the following diagrams provide an overview of which software components were generated and where they can be found in the project. Understanding what gets generated (and where) will help you find the individual or set of software components that you want use in your own developent projects.

Scaffolding Note

In order to ease your way into code generation with ME4S, this tutorial only involved scaffolding from 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 will be a lot more software components generated than what was generated with this tutorial. Even though there’s a lot more code, it will all be grouped and organized as shown in the following diagrams.

Figure 20. What’s generated with Spring MVC Scaffolding (part 1)

 

Figure 21. What’s generated with Spring MVC Scaffolding (part 2)

 

The Spring MVC scaffolding blueprint provides a snapshot of what gets generated during scaffolding. The Spring MVC blueprint and the blueprints for the other ME4S code generations capabilities are covered in more detail in the MyEclipse for Spring reference guide. (see Additional Developer Resources).

Figure 22. Spring MVC Scaffolding Blueprint

 

8. Conclusion

Now that you have a running Spring MVC application, you may want re-run the tutorial and scaffold different web clients, including Spring Web Flow, JavaServer Faces (JSF 2.0), Adobe Flex, Google Web Toolkit (GWT), and iPhone.

You may also want to try the Spring Annotator, JAX-WS Annotator and JPA annotator tutorials which are available in the Eclipse help system and online (see Additional Developer Resources).

What was your experience with this tutorial? Share your experience with us by completing a very brief survey.

Advertisements
Comments
  1. Ward Tacason says:

    Absolutely pent content material , appreciate it for selective information .

  2. e-tupakka haitat says:

    Absolutely indited subject matter, Really enjoyed reading.

  3. certified nurse assistant says:

    You can certainly see your expertise in the work you write. The world hopes for more passionate writers like you who are not afraid to mention how they believe. Always go after your heart.

  4. teething remedies says:

    I was looking at some of your blog posts on this site and I conceive this web site is real instructive! Keep on putting up.

  5. film izle says:

    oh my god superb submit admin will examine your webpage generally

  6. carolina kia greensboro says:

    Thanks for the sensible critique. Me & my neighbor were just preparing to do some research about this. We got a grab a book from our area library but I think I learned more clear from this post. I’m very glad to see such magnificent information being shared freely out there.

  7. broadjam scam says:

    Just wanna tell that this is extremely helpful, Thanks for taking your time to write this. “We do not attract what we want, But what we are.” by James Allen.

  8. hybrid car fire says:

    Very interesting details you have observed, thanks for putting up.

  9. cheap vacations says:

    What i don’t understood is in fact how you’re no longer actually much more well-liked than you may be right now. You’re very intelligent. You understand thus considerably in relation to this topic, made me in my opinion consider it from so many various angles. Its like women and men are not involved unless it is one thing to do with Woman gaga! Your personal stuffs outstanding. At all times care for it up!

  10. auto approved list says:

    Cool text dude, keep up the great work, just shared this with the mates

  11. cooper apartments paris says:

    Greetings from Los angeles! I’m bored at work so I decided to browse your blog on my iphone during lunch break. I love the information you provide here and can’t wait to take a look when I get home. I’m amazed at how quick your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyhow, excellent site!

  12. microsoft dynamics gp training says:

    Thank you for the auspicious writeup. It in truth used to be a enjoyment account it. Look advanced to far introduced agreeable from you! However, how could we be in contact?

  13. media electric fireplace says:

    You have brought up a very great points , thankyou for the post.

  14. music licensing publishing says:

    Interesting thesis. Interestingly thought out and presented, carrying forth interestingly for those who take note and are of good nature and interest.

  15. Jenae Stuber says:

    Hey There. I discovered your weblog the use of msn. This is a very well written article. I will make sure to bookmark it and return to read extra of your useful information. Thank you for the post. I’ll definitely return.

  16. mature porn video says:

    I was seeking for this wonderful sharing admin very much thanks and also have nice blogging bye

  17. Scrapebox says:

    I love the efforts you have put in this, thanks for all the great content.

  18. four micro onde says:

    I like this weblog its a master peace ! Glad I discovered this on google. “Don’t spend time beating on a wall, hoping to transform it into a door.” by Dr. Laura Schlessinger.

  19. microsoft dynamic says:

    I really like your writing style, superb info, appreciate it for posting :D. “All words are pegs to hang ideas on.” by Henry Ward Beecher.

  20. accelerated nursing programs says:

    What i don’t realize is in truth how you are no longer actually a lot more well-favored than you might be right now. You’re very intelligent. You recognize therefore considerably relating to this matter, made me personally consider it from so many numerous angles. Its like women and men are not involved unless it is something to accomplish with Lady gaga! Your individual stuffs great. Always maintain it up!

  21. Marx says:

    Some really nice and utilitarian info on this site, also I conceive the style and design has got good features.

  22. kelsey cooper berkeley says:

    Regards for this fantastic post, I am glad I noticed this web site on yahoo.

  23. television sets says:

    Its perfect time to make some plans for the future as well as its time to be at liberty. Ive see this post in case I can I would like to suggest you few interesting things or advice. Maybe you could write next articles talking about the next few paragraphs. I aspire to read more reasons for it!

  24. How to Index Backlinks says:

    I like this web blog very much, Its a rattling nice situation to read and incur info. “Dead battles, like dead generals, hold the military mind in their dead grip.” by Barbara Tuchman.

  25. credit card holder says:

    hi!,I really like your writing so much! proportion we keep up a correspondence extra approximately your post on AOL? I require a specialist in this area to unravel my problem. Maybe that’s you! Looking forward to peer you.

  26. disque dur externe pas cher says:

    Regards for all your efforts that you have put in this. Very interesting info. “Live with men as if God saw you converse with God as if men heard you.” by Seneca.

  27. blackjack gum says:

    Only a smiling visitor here to share the love (:, btw great style .

  28. best hybrid cars says:

    Very interesting points you have mentioned, regards for posting.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s