IBM DeveloperWorks Spring Roo Part 5 : Writing Advanced and Wrapper Addons

Today fifth part of my Spring Roo series got published at IBM DeveloperWorks. This article-cum-tutorial talks about how you can write advanced and wrapper Spring Roo add-ons. Checkout the article at

Spring Roo PGP Exception

Today when I fired Spring Roo shell I started getting exception as shown below and I was not able to execute any command. I uninstalled Spring Roo (thinking that it might have got corrupted) but it didn’t helped after lot of firefighting I figured out the solution to overcome this problem. The problem was that yesterday I trusted some pgp keys and somehow Roo was not able to find them and started throwing exception. The solution is to remove a file name .spring_roo_pgp.bpg and restart Spring Roo. Spring Roo will create a new clean file. Continue reading “Spring Roo PGP Exception”

Fixing Exception — Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)

If you are working with Spring Roo and suddenly start getting exception “Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)” then make sure you have _Configurable.aj ITD in your project. This ITD makes the sure that your entity classes have all the required dependencies like EntityManager injected in them. Configurable ITD  looks like as shown below

privileged aspect Movie_Roo_Configurable {

    declare @type: Movie: @Configurable;


Spring Roo 1.1 Cookbook Review

This review is about Spring Roo 1.1 Cookbook by Ashish Sarin from Packt Publishing. Before I get into details lets me first tell you what is Spring Roo in case you don’t know.

Note : I am author of Spring Roo series on IBM DeveloperWorks.

What is Spring Roo?

Spring Roo is a lightweight productivity tool for Java™ technology that makes it fast and easy to develop Spring-based applications. Applications created using Spring Roo follow Spring best practices and are based on standards such as JPA, Bean Validation (JSR-303), and Dependency Injection (JSR-330). Roo offers a usable, context-aware, tab-completing shell for building applications. Spring Roo is extensible and allows add-ons, enhancing its capability.

Book Details

  1. 7 chapters covered in 460 pages. Each chapter has some recipes and each recipe is divide into four parts — Getting Started, How to do it, How it works, and there’s more. So each recipe give you all the details required from getting started to details related to how it works. I liked this approach.
  2. Book costs $44.99
  3. This book covers Spring Roo in detail.


  1. Recipes represents solution to real world problems. This book covered how to define composite keys, talked about how you can use JNDI datasource, how you can create application which has to interact with multiple databases etc. These are the problems you will face in real world and this book tries to answer them.
  2. The two chapters I liked the most are chapter 3 and 4 which covered Advanced JPA and Spring MVC web applications. Chapter 3 covered in detail how you can create many-to-one, one-to-many relations, create mapped super class etc. Chapter 4 gives you all detail you need to create Spring MVC application and customize them according to your requirement.
  3. This book from the start talks how different features are provided by Spring Roo through Add-ons. I think it is very important to share Spring Roo add-on architecture from the start as this tells you that you can extend Spring Roo by writing your own add-ons.
  4. The book not only covers Spring Roo but also provides good introduction to the technologies it uses.
  5. Chapter 6 gives good introduction to technologies like Solr, GAE, JMS. It really shows the power of Spring Roo.
  6. I think this book does good justice to the power of Spring Roo.


  1. One thing that I was looking forward was customizing GWT applications. This book talked in detail about the GWT application created about Spring Roo but does not cover how to customize the GWT app.
  2. Same is the case with the 7th chapter which cover writing add-ons. The book cover in good detail the default add-on generated by Spring Roo but does not shows how you can customize them to write your own add-ons.
  3. This book is based on Spring Roo 1.1.5 Release version but recently Spring Roo has released 1.2 version. Some commands talked in this book are deprecated and are not the recommended now. Also, lot of new features like MongoDB support, JSF support , multi module projects etc. are not there.


Overall I liked the book and I think it is a good book to read if you are thinking of using Spring Roo in future. Yes it is missing some new features but if you will not be using those features this book is a good buy.

Spring Roo CompareTo Add-on Released

Over the weekend I created an advanced Spring Roo add-on to provide support for creation of compareTo method. This add-on is on similar lines of Spring Roo own equals add-on which provide implementation of equals and hashcode methods. The add-on is released and available for community to use. The add-on is listed in Spring Roo repository XML . It is built using Spring Roo latest version 1.2.0.RC1. This post will talk about how to install and use the add-on.

Installing the compareTo add-on

Open the operating system command line and type roo. In case you don’t have Spring Roo setup please refer to my IBM DeveloperWork article on Spring Roo. After the roo shell initiates type the following command to install the add-on.

addon install bundle --bundleSymbolicName org.xebia.roo.addon.compareto

If you don’t have automatic pgp trust enable you will see a message on Roo shell saying that you first have to trust my pgp key before you can install the add-on. To trust the key type the following Roo command.

pgp trust --keyId 0x9B68220C

Once it is enable re-run the addon install command and add-on should get installed. To verify that add-on is installed type the osgi ps command and you should compareto add-on listed at the bottom of the command output.

[  78] [Active     ] [    1] spring-dw-roo-compareto-addon (0.1.1.BUILD)

This add-on exposes two commands compareto setup and compareto and these commands are enabled after you have created entity. This is because before you have created any entity it does not make sense to have compareTo method.

Using the compareTo add-on

Lets first create a simple bookshop application. Type the following command which will create the project, setup database and create a simple book entity.

project --topLevelPackage com.xebia.bookshop --projectName bookshop
jpa setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE
entity jpa --class ~.domain.Book --testAutomatically
field string --fieldName title --notNull
field string --fieldName author --notNull
field number --type double --fieldName price --notNull

After you have ran the commands above you can now create compareTo method for book entity.To create the compareTo method type the following commands.

compareto setup
compareto add --type ~.domain.Book

The first command will add the required dependencies and second will create the Book_Roo_Compareto.aj ITD which contains the compareTo method.

If you want to exclude some fields in compareTo method you should specify i.e. if you don’t want author and price field to be used in compareTo method you can specify them in excludeFields attribute as shown below.

compareto add --type ~.domain.Book --excludeFields "author price"

Use this add-on and share feedback.

IBM DeveloperWorks Introducing Spring Roo, Part 4: Rapid application development in cloud with Spring Roo and Cloud Foundry

Take the rapid development of Roo a step further by creating applications to work in the cloud with Cloud Foundry, the first open platform as a service project created by VMWare. Learn more about the environment and then deploy an application into Cloud Foundry using the Roo shell. Read about it here

Introducing Spring Roo, Part 3: Developing Spring Roo add-ons

Spring Roo is a RAD tool that lets you build applications (mainly web) quickly and easily. Under the hood, Spring Roo is based on OSGI add-on architecture, which makes it easy to extend Spring Roo by adding add-ons. Spring Roo provides commands to create add-ons that can be very easily made available to the Spring Roo user community. In this article, we first talk about Spring Roo architecture, talking about how Spring Roo leverages its own add-on architecture to provide different features, then we will create add-ons using the Roo shell and modify them to suit our needs. Please read the third article at IBM DeveloperWorks.

Creating Application using Spring Roo and Deploying on Google App Engine

Spring Roo is an Rapid Application Development tool which helps you in rapidly building spring based enterprise applications in the Java programming language. Google App Engine is a Cloud Computing Technology which lets you run your application on Google’s infrastructure. Using Spring Roo, you can develop applications which can be deployed on Google App Engine. In this tutorial, we will develop a simple application which can run on Google App Engine.
Read more