Spring roo

Proof-of-Concept Using Spring Roo

by on January 20, 2014 12:00 pm

In my time with Keyhole, I’ve been involved in a number of projects where the client was asking us to rewrite a legacy system while retaining their existing database. Sometimes it helps to give a quick demo on how using current technologies can make it easier to develop, test, and maintain their code.

One way I’ve found to get a quick example created (that is relevant to the project at hand) is to use Spring Roo. Its ability to reverse engineer a data model from an existing database schema certainly comes in handy.

Here are the steps to do this when your client is using an Oracle database:

1. While Spring Roo is accessible with just a command prompt, it’s much easier to use an IDE and the easiest one to use for this task is Spring’s own Eclipse-based IDE, Spring Tool Suite (STS). You can download the latest version from http://spring.io/tools.

STS Download Page

2. Once you’ve downloaded and set up STS, hit Ctrl-N to bring up the New wizard (or you can select File –> New –> Other…). Type “roo” into the filter and select “Spring Roo Project”. Click “Next”.

Spring Roo Project

3. For now, just fill in the first two fields with an appropriate project and package name. The defaults will work for the rest of the fields. Click “Next” again and then click “Finish” to create the new project.

Spring Roo Project wizard
Spring Roo Project wizard finish

4. What should happen is that your project will come up with a view labeled “Roo Shell”. Normally, it hangs trying to open that view. So I close that view, then right-click on your new project and choose “Spring Tools –> Open Roo Shell”. This time it should come up quickly and look like this.

Roo Shell

5. Now we let Roo do its job and lead us down the path to a fully set up project. Go ahead and enter “hint” on the Roo command line. It tells us that we need to set up a persistence configuration, so let’s follow the suggestions it gives us.

Roo Shell hint

6. For this particular example, I’m using an Oracle database with EclipseLink as the persistence provider but there are a number of options and Roo will show them to you when you hit Ctrl-Space at the Roo command prompt.

Roo Shell database setup

7. You’ll see that Oracle has made things a little bit difficult on us by not making the driver publically available. You can learn how to create an OSGI-wrapped version of the Oracle driver that can be installed and used by Roo in a blog post by technical consultant Kerry Wilson at http://www.goodercode.com/wp/spring-roo-database-reverse-engineer-with-oracle/.

Roo Shell database driver

8. Finally, we’re ready for the good part. Enter the command “database reverse engineer –package ~.domain –schema PUBLIC” into the Roo command prompt, where “domain” is the package name where you want your models created and “PUBLIC” is the name of the schema you want to reverse engineer.

9. Roo will do some work and when it’s finished you’ll have POJOs that represent your database tables with JPA annotations for the fields and relationships. If the database is anything more than a very simple model, it’s very likely that Roo got something wrong. However, you did just save yourself hours of creating entities for each table in the schema so you can spend some of that time fixing Roo’s mistakes.

Final Notes

While I’ve only talked about how Roo can be used to map a database schema to a Java entity model, Roo is also useful for getting the initial configuration set up for a number of web technologies. It can create unit tests, add logging, integrate with GWT, JSF, JMS, Solr, Spring MVC, and others. Best part, especially if you aren’t using Roo on the full project, is that all of the Roo annotations can be removed and you’re left with pure Java code that can be the base of your new project.

- Brice McIver, asktheteam@keyholesoftware.com

  • Share:

One Response to “Proof-of-Concept Using Spring Roo”

Leave a Reply

Things Twitter is Talking About
  • Want to write a single page app with #ExtJS? View @zachagardner's video tutorial series to get you started: http://t.co/XFYDT6YNWA
    July 29, 2014 at 3:50 PM
  • A #JavaScript promise is an I.O.U. to return a value in the future. Learn about them: http://t.co/6wCz9b7e4v
    July 29, 2014 at 1:36 PM
  • A huge welcome to John Holland who joined the Keyhole team today!
    July 28, 2014 at 4:56 PM
  • We think #JavaScript Promises are cool. Here's a good introduction from @mauget - http://t.co/6wCz9b7e4v
    July 28, 2014 at 2:19 PM
  • There's a new post on the Keyhole blog by @mauget: #JavaScript Promises Are Cool - http://t.co/6wCz9b7e4v
    July 28, 2014 at 9:52 AM
  • Thank your #Sysadmin - today is System Administrator Appreciation Day. http://t.co/LcvDNa9kPg
    July 25, 2014 at 8:05 AM
  • @rickincanada Thx for your tweet! Shoot us an email at asktheteam@keyholesoftware.com so we can set up a time to talk. Have a good day.
    July 24, 2014 at 3:33 PM
  • Never used JAXB? Check out a simple usage pattern that pairs #JAXB’s data binding capabilities with JPA - http://t.co/Ki9G04HV5e
    July 24, 2014 at 9:53 AM
  • Guess what today is? Tell An Old Joke Day - http://t.co/835ORWMX6N! So, why do programmers always confuse Halloween & Xmas? 31 Oct = 25 Dec
    July 24, 2014 at 8:45 AM
  • MT @midwestio: Posted another #midwestio talk recording to our YouTube channel: @MinaMarkham on modular CSS. Watch: http://t.co/aU3LpfUoi4
    July 24, 2014 at 8:25 AM
  • We just posted pictures from our National Hot Dog Day Lunch Cookout. Check them out - http://t.co/To06plaw1C
    July 23, 2014 at 4:14 PM
  • Good free cheat sheet - #Java Performance Optimization Refcard from @DZone: http://t.co/7vBgsmqy08
    July 23, 2014 at 10:48 AM
  • Did you know today is a holiday? It's National Hot Dog Day! We're gearing up for our team lunch hot dog cookout & can't wait to celebrate.
    July 23, 2014 at 9:43 AM
  • Check out our newest blog: #JAXB – A Newcomer’s Perspective, Part 1 http://t.co/Ki9G04HV5e
    July 22, 2014 at 1:22 PM
  • New post on the Keyhole blog by Mark Adelsberger: #JAXB – A Newcomer’s Perspective, Part 1 http://t.co/Ki9G04HV5e
    July 21, 2014 at 2:27 PM
  • If you're a Java dev, you're likely familiar with Annotations. But have you created your own #Java Annotations? Ex - http://t.co/BgCsYjxZKF
    July 18, 2014 at 12:10 PM
  • RT @gamasutra: Don't Miss: Unconventional Tips for Improving your Programming Skills http://t.co/6TFox7CKHU
    July 16, 2014 at 3:20 PM
  • We're about to send out our free monthly tech newsletter. Dev tips/articles via email. Not on the list yet? Sign up - http://t.co/F8h0NSiicZ
    July 15, 2014 at 11:57 AM
  • Have you ever tried creating your own #Java annotations? See a situation where it was beneficial - http://t.co/BgCsYjxZKF
    July 15, 2014 at 8:36 AM
  • There's a new post on the Keyhole blog by @jhackett01: Creating Your Own #Java Annotations - http://t.co/BgCsYjxZKF
    July 14, 2014 at 1:43 PM
Keyhole Software
8900 State Line Road, Suite 455
Leawood, KS 66206
ph: 877-521-7769
© 2014 Keyhole Software, LLC. All rights reserved.