Copyright © 2010 Skyway Software
Table of Contents
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.
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).
The prerequisites needed to complete this tutorial are:
Download MyEclipse for Spring 10.0
Create a MyEclipse Web Project (or Eclipse Dynamic Web Project) called MySpringProject.
The next step is to initialize the project for Spring and Spring code generation.
Right-click on the MySpringProject project, and choose MyEclipse > Add Spring Code Generation Capabilities...
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
The resources folder was also created and setup as an Eclipse source folder. This is where all application configuration files are generated to.
You will notice that various files were generated into the resources folder. Here's a summary of the generated files.
Table 1. Generated Resources
|hibernate.properties||Hibernate configuration file|
|jta.properties||Java Transaction API (JTA) configuration file; by default generated to use Atomikos|
Log4J configuration file
Data Access Objects configuration file
A set of Spring context files for Spring configurations that are generated.
A set of Spring context files for Spring configurations that are manually added by a developer.
Java Persistence API (JPA) configuration file.
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.
Table 2. Summary of Web Content Updates
|web.xml||Added references to Spring servlet RequestContextListener, ContextLoaderListener, DispatcherServlet and ResourceServlet.|
|applicationContext.xml||Default Spring context file with references (imports) to the other bootstrapped context files|
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.
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.
Thank you for you interest in MyEclipse for Spring. If you are interested in learning more, the following developer resources are available:
Reference - Eclipse Help (MyEclipse for Spring 10.0 --> MyEclipse for Spring Reference) or Education Materials (online)
Tutorials - Eclipse Help (MyEclipse for Spring 10.0 --> Tutorials) or Education Materials (online)
Screencasts - MyEclipse for Spring YouTube Channel (online)
Support Forums - MyEclipse for Spring Forums (online)
Blog - MyEclipse for Spring Posts (online)