Raging Goblin

28 February 2013

Spring Roo 1: The basics

Filed under: Java,Spring Roo — Raging Goblin @ 10:56
Tags: ,

Previous year I looked into Spring Roo with a couple of colleagues and tried to examine the basics of this framework. In a few posts I want to share what we learned. In this post I will only cover the standard stuff, so nothing outside what is pretty well documented will appear here, but it will provide a foundation for later rants.

We are going to make a very simple web application, a logbook. Users will be able to login and scribble notes in a simple textfield and can attach a date value to it. Sounds simple he? To be honest it is, look at the database model:

Database model

We have a class LogUser with a username and password and a class LogItem with the logmessage and a creationDate. A many to one relationship exists between the Logitem and the LogUser to indicate that every LogItem belongs to one specific LogUser.

Spring Roo comes with a handy feature to run a script. So if you run the following script the application will be created for you in a raw form:

project --topLevelPackage raging.goblin.roo --projectName logbook
jpa setup --database MYSQL --provider HIBERNATE 
properties set --name database.properties --path SPRING_CONFIG_ROOT --key database.url --value jdbc:mysql://localhost:3306/logbook
properties set --name database.properties --path SPRING_CONFIG_ROOT --key database.username --value root
properties set --name database.properties --path SPRING_CONFIG_ROOT --key database.password --value root
entity jpa --class ~.domain.LogItem
field string --fieldName message
field date --fieldName creationDate --type java.util.Date
entity jpa --class ~.domain.LogUser
field string --fieldName username
field string --fieldName password
focus --class ~.domain.LogItem
field reference --fieldName logUser --type ~.domain.LogUser 
test integration 
focus --class ~.domain.LogUser
test integration 
web mvc setup
web mvc scaffold --class ~.web.LogItemController --backingType ~.domain.LogItem

Note the username, password and database connection, alter these to fit to your own settings as these are clearly not meant for production systems ;).

The only thing we have to change is the fact that Spring Roo generated user fields in the views for the LogItems. Now import the contents in Eclipse* as a maven project (file -> import -> existing maven projects -> browse to project folder). Change the rendering of every view residing in ~/workspace/logbook/src/main/webapp/WEB-INF/views/logitems by setting the ‘z’ to ‘user-managed’ and ‘render’ to ‘false’, e.g. in ~/workspace/logbook/src/main/webapp/WEB-INF/views/logitems/show.jspx

<table:column id="c_raging_goblin_roo_domain_LogItem_logUser" property="logUser" z="user-managed" render="false"/>

Run the application with the command ‘mvn jetty:run’ and browse to localhost:8080/logbook:


Next time we will explore how to provide security with a login and a database backend.

* This can either be Eclipse with the m2e plugin or the Spring Source Toolsuite as provided by SpringSource.



  1. […] the previous post we created a very simple logbook. In this post we will secure it to keep your logs […]

    Pingback by Spring Roo 2: Spring Security with database backend | Raging Goblin — 8 March 2013 @ 11:07 | Reply

  2. […] post 1 we created a simple log application that is capable of storing messages in a database. In post 2 we […]

    Pingback by Spring Roo 3: Show only items belonging to logged in user | Raging Goblin — 18 March 2013 @ 11:58 | Reply

  3. […] There is no need to show the password of a LogUser as it is encrypted anyway. So remove it from the views by setting ‘z’ to ‘user-managed’ and ‘render’ to ‘false’ in the same fashion as we did in Spring Roo 1: The basics. […]

    Pingback by Spring Roo 4: User management | Raging Goblin — 3 April 2013 @ 19:48 | Reply

  4. Excellent post…keep doing

    Comment by Sudhanshu — 10 April 2013 @ 20:27 | Reply

  5. Please update more on Spring Roo

    Comment by Sudhanshu — 10 April 2013 @ 20:30 | Reply

  6. […] Today a short post about the representation of enums in Spring Roo and internationalization. First, we are going to add an enum (Gender) to our application: […]

    Pingback by Spring Roo 6: Representation of enums and internationalization | Raging Goblin — 18 April 2013 @ 20:34 | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

%d bloggers like this: