Time to get started. I'm going to run through the introductory materials on building a
Spring Roo application with the
Google Web Toolkit front end. I will be using the Spring Tools Suite as the IDE (based on Eclipse).
I will start by following some initial advice:
Installation
What I have
- Java 6 SDK r26 from here
- SpringSource Tool Suite: Version: 2.7.1.RELEASE: Build Id: 201107091000
- Using Google Suite Plugin Version 2.3.3.r36v201107211953
- Spring Roo (latest production release) 1.1.4 RELEASE
I got Spring Tool Suite bundled with Google Integration from
here
After running STS, go to the dashboard and select the 'extensions' tab (bottom). Find and Check Google Plugin for Eclipse and press 'Install' (bottom left)
Restart STS and thats it (for now)
Overview of Spring Pizza Shop Demo
Lets use the
Spring Framework Roo tutorial to get started.This tutorial walks us through creating a Roo project including entities controllers and the UI/scaffold. I will try to emphasise use of the STS tool as well as focusinging on using GWT as the front end. To begin with, we will follow the tutorial fairly closely.
Here is the project UML from the spring tutorial that we will create
This is the Roo Pizza Shop demo

First Step Basic Roo Configuration
Spring Roo builds upon Spring framework 3.0 with JPA 2.0. It uses a command line tool to create basic elements of a project, from persistence setup, to creating entities, to creating Spring MVC controllers, to generating Scaffold ui (in our case using GWT).
We can use spring STS to create a new spring Roo project project

- From the Dashboard, select Create a Spring Roo Project
- Fill out dialog: Project Name: pizza, top level package: com.springsource.roo.pizzashop
- Accept all other defaults and press Next (and then Finish). This will create the Roo project and open the roo shell. Actually, STS is executing the roo shell to create the project directory and the roo command:
roo> project --topLevelPackage com.springsource.roo.pizzashop
We see the ROO command shell at the bottom with a command promt inviting us to execute roo commands.
The window has a top part showing a console with roo commands as well as a prompt, but don't be fooled. The roo prompt we use in StS is below (a single line edit).
The spring ROO project leverages Maven2 and its unique project structure.
One cool roo command you will use right away is hint. This will give you possible options to do from the point in your project. In this case,
- type HINT and press enter, Roo Shell will respond with a suggestion to do 'persistence setup'
- type' persitence setup' and press ctrl+space. In StS, this will use code assist to allow you to select possible next options for the command (the command line, you press the TAB key). In this case we will select --provider HIBERNATE and --database HYPERSONIC_IN_MEMORY
- The complete roo command is:
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
- Roo will generate the JPA configuration files and initial spring context
Next: Create an Entity
Now we are ready to create some entities and fields
- Press Hint again, and Roo will advise you to type ent and press TAB to get the next option (from STS, ctrl+space). This will allow us to create an entity with a specific class name: Topping
- Type entity then press (ctrl+space) . This will produce --class
- Type ~.domain.Topping for the class name (the tilda will indicate the project's package root (remember we specified com.springsource.roo.pizzashop)
- Now ctrl+space doesn't give us more hints since all required options are satisfied, but type double dash (--) and then ctrl+space will give us a bunch more options.
- type or select --testAutomatically to generate test classes for the new entity and press enter (the ccomplete roo command: entity --class ~.domain.Topping --testAutomatically)
Roo creates a whole bunch of files and aspects. Notice the actual entity "SRC_MAIN_JAVA\com\springsource\roo\pizzashop\domain\Topping.java" is created. You can see it in the packag tree. However, STS starts with an inital filter in the package tree to 'Focus on Active Task'.

Click the filter icon in the top toolbar of the Package view to reveal the entire project. Now navigate to src/main/java. See the com.springsource.roo.pizzashop.domain package and the created Topping.java class just created.
Next: Create Fields for Our Entity
Now lets add a field. Use the roo command to type field string --fieldName name --notnull --sizeMin 2
THis will add a field, and update/add to the generated aspects based on the annotaitions.
Opening this class, all you see is
Notice the classs annotations that roo adds @RooJavaBean, @RooToString and @RooEntity. These annotations generate aspects with extensions .aj for inter type definitions. Spring also adds JSR 303 bean validation annotations on the field based on the options we specified: @NotNull and @Size(min = 2).
The principle that Roo introduces here is the heavy leveraging of AspectJ's Inter-Type Declaration (ITD). The ITD code generates as a separately complied file, but is encorporated into the class byte code of the advised class. Generally we don't need to bother about what is generated here. But lets look anyway. For instance, the @RooJavaBean annotaion creates the class Topping_Roo_JavaBean.aj. Peeking at it, we see:
File: Topping_Roo_Entity.aj
We see that the name field produced a getter and a setter for the field. As we add new fields, this aspect will be updated. Using aspects this way allows the domain class to remain particularly pure.
As another example, lets look at what was generated for the @RooToString annotation:
File: Topping_Roo_ToString.aj
Finally, lets' look at what Roo does with the @RooEntity declairation
File: Topping_Roo_Entity.aj
Rather than creating a data access object (DAO) or service, Roo assumes that each entity created has its own implementation of persistence. The @RooEntity annotation generates a ITD (Inter-type Declairation) for the entity advising it to add many methods to support persistence, inclding id generation, versioning, access to the entity manager, various transactional methods:
- persist,
- remove,
- flush,
- merge,
- clear
and various finder methods
- count
- find by id
- findAll
- and pagable findAll
Next: Some More entitles and fields
As Roo creates objects, it keeps track of the last object you created. The next command defaults to this target, so there is no need to specify it explicitly. For example, when we created the field, we didn't need to specify what class to create the field for. It assumed we meant the last entity we worked with.. The spring Roo console shows what entity we last worked with in its prompt, much like a command shell might with a prompt showing the current directory path.
Now lets create another entity and some fields similar to the ones we created before. Here are the Roo commands:

That's it. As long as we follow the defaults, things are easy. This is the approach taken by Ruby on Rails: convention over configuration. The command line invokes templated commands to create objects quickly.
Our project should look basically like this (as seen from the project view)
Next: Some Relationships for our Entities
We are still in JPA land. JPA allows us to create relationships as well as if POJO java classes using well known collections. Roo supports a one-to-one or many-to-one reference, a one-to-many 'set' (and also ways to create many-many). In the above, we have a one-many relationship from Pizza to Topping (a pizza has many toppings) and a one-one relationship (reference) to a base. We'll use the Roo command shell to create these too. The tutorial shows there are two relationships from Pizza, a 'reference' to a base (m:1) where a Pizza has one base, and a set of toppings (m:m relationship to toppings), where a pizza has a set of toppings.
The above commands assume you are creating the relationship fields to the last entity you created: Pizza as it would show you in a command prompt. If not, make sure to append --class ~.domain.Pizza to the above commands (at least the first one) to assure the relationships are created for the Pizza class.
And we can finish up with PizzaOrder
Notice the last command creates another relationship, this time an PizzaOrder has a set of Pizzas ordered, which Roo will create a m:m relationship for of type Set pizzas. As you can see, creating entities, fields and relationships with Roo comes down to running a set of commands to generate the appropriate Java code and Aspects according to Roo convention. In fact, you can save these commands as a 'seed' text file that will create a project for you, generating the project structure, configruation, classes and aspects required.
Next: Lets Test
We can now run the integration tests using the roo command perform tests.
Finally: Look at the test classes generated