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
  • 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
  • We love development! Have you seen our weekly team blog? We show how to be successful with the tech we use. See it - http://t.co/nlRtb1XNQH
    July 12, 2014 at 2:35 PM
  • Rapid appdev has a bad rep, but there are ways to bring development time down the right way. Don't Fear the Rapid - http://t.co/aTPcAKOj0r
    July 11, 2014 at 3:10 PM
  • Automated Testing is great for dev, but does bring a set of challenges (especially for #agile teams). Success tips: http://t.co/1acl1ngO7i
    July 11, 2014 at 12:16 PM
  • This is fantastic - One small step for Google, one giant leap for empowering girls to code: http://t.co/R90V5DBkv1
    July 10, 2014 at 2:52 PM
  • #RabbitMQ: messaging software built on AMQP protocol. Learn relevant concepts & how to avoid common "gotchas" here: http://t.co/ZwMXlhKyX8
    July 10, 2014 at 9:31 AM
  • A huge welcome to Brian Wetzel who joins the Keyhole team today!
    July 10, 2014 at 8:50 AM
  • Seen our newest blog? @joshuarob01 talks the challenges #Agile teams face in automated testing & how to solve them: http://t.co/1acl1ngO7i
    July 9, 2014 at 3:51 PM
  • How can we ensure that we write unit tests with sufficient coverage? Here are some tips for success in #unittesting - http://t.co/GGTEGEQFtk
    July 9, 2014 at 3:05 PM
  • Are you a .NET dev who likes working with #JavaScript, #Angular & a solid team? Join Keyhole: http://t.co/kWgVdxgvpG http://t.co/VLoeULthOE
    July 9, 2014 at 8:48 AM
  • Counting down until the Keyhole Team Happy Hour this evening @ the District. Pour House + Kitchen... one more hour!
    July 8, 2014 at 4:15 PM
  • Code For Maintainability So The Next Developer Doesn't Hate You - http://t.co/FWTMF7Pixd 8 helpful tips to do so.
    July 8, 2014 at 2:05 PM
  • So glad you enjoyed it! @AssertAgile: "Nice article, sounds familiar to me: Lessons Learned in Automated Testing - http://t.co/1acl1ngO7i"
    July 8, 2014 at 1:54 PM
  • Good tutorial: creating a TV show tracker with #AngularJS, Bootstrap, Node, MongoDB, Passport & gulp.js - http://t.co/meXZDazxFr
    July 8, 2014 at 12:07 PM
  • Ever cut-&-paste a function that does almost what you need? Seems harmless, but comes back to bite. Tips to help - http://t.co/hruOou33As
    July 8, 2014 at 10:40 AM
Keyhole Software
8900 State Line Road, Suite 455
Leawood, KS 66206
ph: 877-521-7769
© 2014 Keyhole Software, LLC. All rights reserved.