MyEclipse Logo

MyEclipse for Spring 8.6: Spring DSL Tutorial (Part 1 of 2) - Enable Spring DSL

How to enable the Spring DSL capabilities on a project

Abstract

This tutorial details the steps required to bootstrap a web project with Spring support using MyEclipse for Spring.


Table of Contents

1. Introduction
2. Goal
3. Prerequisites
4. Create Web Project
5. Initialize Project
6. Review the output
7. Conclusion
8. Additional Developer Resources

1. Introduction

The Add Spring Code Generation Capabilities wizard of MyEclipse for Spring is used to bootstrap a project for Spring and add Spring code generation functionality to a project. This wizard has various capabilities (some optional) that can be added to the current project, including:

  • adding Spring application runtime dependencies to project

  • bootstrapping the project with required Spring configurations

  • enabling Code Generation Builder for automated code generation

  • enabling Code Synchronization Builder for automated reverse engineering of Spring/Java artifacts

  • enabling the Spring DSL, including enabling Spring DSL view in the project

  • applying Spring Nature to project for viewing and editing Spring configuration via Spring Elements node

  • enabling code generation by application layer (web, service, domain and DAO)

  • configuring target projects and folders for code generation

By default this wizard is setup with conventional defaults which enable all options. When clicking on Finish from the Setup panel, all the default configuration options will be applied to the current project. In order to customize the configuration, there are seven optional steps to the wizard.

2. Goal

This tutorial is going to walk you through bootstrapping a project for Spring and Spring code generation.

MyEclipse for Spring will be used to do bootstrap the project within a matter of minutes (in technically two mouse clicks).

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 MySpringProject.

5. Initialize Project

The next step is to initialize the project for Spring and Spring code generation.

  1. Right-click on the MySpringProject project, and choose MyEclipse > Add Spring Code Generation Capabilities...

    Add Spring Code Generation Capabilities Wizard

    Figure 1. Add Spring Code Generation Capabilities Wizard


  2. The first panel is for specifying whether the Spring Nature should be applied to the project. This option is disabled by default. For this tutorial we'll keep it disabled. Click the Next button.

    Basic Setup

    Figure 2. Basic Setup


  3. The Web Layer Generation panel is used for enabling and configuring code generation for the web layer of a Spring application. By default it is enabled, and you can specify the project and folders to generate to. For this tutorial we'll use the defaults.

    Initialize web layer

    Figure 3. Initialize web layer


    The source, resources and content folders can be any folder in the "target project". If the folders don't exist, they will be created. In the case of the source and resources folders, they will also be configured as Eclipse source folders in the project. Since this project is a web project, the content folder is automatically set to the content folder that was specified in the New Web Project wizard. Click the Next button.

  4. The next three panels are nearly identical to the Web Layer generation panel, however these panels are used to configure the other layers of a Spring web application. By default the other layers are also enabled, and the source and resource folders are the same as the web layer. For this tutorial we'll use the defaults. Click the Next button.

    Initialize service, domain and DAO layers
    Initialize service, domain and DAO layers
    Initialize service, domain and DAO layers

    Figure 4. Initialize service, domain and DAO layers


  5. The Runtime Dependencies panel is for adding Spring and dependent libraries to the current project. While you can add and remove libraries from the project by hand, this panel can bootstrap the project with a full set of libraries typically needed by a Spring application. In addition to deciding which libraries are added, you can also specify which version of Spring (2.5 or 3.0) that you want to use and how you want the libraries added to the current project. Spring 2.5 and the use of Eclipse classpath containers is the default. Click the Next button.

    Initialize runtime dependencies

    Figure 5. Initialize runtime dependencies


  6. The Summary panel provides a summary of all the actions to be performed by the wizard when the Finish button is clicked. Click the Finish button.

    Review summary

    Figure 6. Review summary


That's it. Your web project is now bootstrapped for Spring and configured for code generation. Since we accepted all the defaults, we could have just clicked Finish from the first panel.

6. Review the output

With just a few clicks there was a lot done to your new web project. In this section of the tutorial we are going to review some of the changes to your project.

  1. The first thing that you will notice is that multiple classpath containers have been added to the project. You now have all the libraries necessary for a Spring web application.

    Classpath Containers

    Figure 7. Classpath Containers


    If you want to see the libraries that are represented by a specific classpath container, you can expand the container to see a list of libraries. For example, if you expand the Spring 2.5 Core Libraries container, you will see the list of libraries that correspond to Spring 2.5 Core.

    Container Libraries - Spring 2.5 Code Libraries

    Figure 8. Container Libraries - Spring 2.5 Code Libraries


    While it's beyond the scope of this tutorial, with MyEclipse for Spring you can also customize the libraries that are in each of these classpath containers.

  2. Per the default configuration of the wizard, the generated folder was created and setup as an Eclipse source folder. This is the folder where generated Java source code will be generated.

    Generated Folder

    Figure 9. Generated Folder


  3. The resources folder was also created and setup as an Eclipse source folder. This is where all application configuration files are generated to.

    Resource folder

    Figure 10. Resource folder


    You will notice that various files were generated into the resources folder. Here's a summary of the generated files.

    Table 1. Generated Resources

    FileDescription
    hibernate.propertiesHibernate configuration file
    jta.propertiesJava Transaction API (JTA) configuration file; by default generated to use Atomikos
    log4j.properties

    Log4J configuration file

    MySpringProject-dao.properties

    Data Access Objects configuration file

    MySpringProject-generated-dao-context.xml

    MySpringProject-generated-security-context.xml

    MySpringProject-generated-service-context.xml

    MySpringProject-generated-web-context.xml

    A set of Spring context files for Spring configurations that are generated.

    MySpringProject-dao-context.xml

    MySpringProject-security-context.xml

    MySpringProject-service-context.xml

    MySpringProject-web-context.xml

    A set of Spring context files for Spring configurations that are manually added by a developer.

    META-INF/persistence.xml

    Java Persistence API (JPA) configuration file.


  4. To web content folder was modified to support Spring web applications. In particular the applicationContext.xml file was added, and the web.xml was updated.

    Bootstrapped Web Content

    Figure 11. Bootstrapped Web Content


    Table 2. Summary of Web Content Updates

    FileDescription
    web.xmlAdded references to Spring servlet RequestContextListener, ContextLoaderListener, DispatcherServlet and ResourceServlet.
    applicationContext.xmlDefault Spring context file with references (imports) to the other bootstrapped context files

  5. The Spring DSL View was added to the project, and it can be seen using the Project Explorer. The Spring DSL shows a hierarchical view of the project's Spring DSL artifacts, and it can be used for configuring the Spring DSL and managing any Spring DSL artifacts.

    Spring DSL View

    Figure 12. Spring DSL View


7. Conclusion

With your Spring web project bootstrapped, now you can start developing your Spring web application. MyEclipse for Spring offers additional features to help you with creating your application. To get started on these other features, take a look at the Spring MVC Scaffolding tutorial and the Spring Editors tutorial. . (see Additional Developer Resources)

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

8. Additional Developer Resources

Thank you for you interest in MyEclipse for Spring. If you are interested in learning more, the following developer resources are available:

Developer Resources