Examining what Spring Roo 1.1.5 creates

Roo is Heaven and Hell.

Heaven is in the demos. It looks great, you can do a basic web application with Java in minutes!

Hell, when confronted with real world problems, and with bugs, but hey, I’ve not given up on it yet, it’s great to set up the basic project structure, and besides, there is always hope for the next version. At present I’m using Roo 1.1.5, which is the latest stable version.

Here my first experiment, a basic web application, I would like to see what Roo creates. I’m assuming that SpringSource Tool Suite is already installed.

From Eclipse Menu, I choose File -> New -> Project… and select Spring Roo Project.

Project name: RooSecurity1
Top level package name: org.obliquid.roosecurity1
[Add project to a working set, if you want]
Next -> Finish

With this first step I already have a mavenized Eclipse project, with a basic Spring setup. Not bad. Let’s see what has been created with a find:

$ find -type f | grep -v target

Eclipse-related files:

./.project
./.settings/org.eclipse.jdt.core.prefs
./.settings/org.eclipse.m2e.core.prefs
./.settings/org.eclipse.core.resources.prefs
./.settings/org.eclipse.ajdt.core.prefs
./.settings/com.springsource.sts.roo.core.prefs
./.classpath

Logging configuration, Spring applicationContext, a Roo logfile and
Maven’s pom.xml

./src/main/resources/log4j.properties
./src/main/resources/META-INF/spring/applicationContext.xml
./log.roo
./pom.xml

The pom.xml comes with the following dependencies:

junit 4.8.2 [test]
log4j 1.2.16
slf4j-api 1.6.1
jcl-over-slf4j 1.6.1
slf4j-log4j12 1.6.1
aspectjrt 1.6.11
aspectjweaver 1.6.11
servlet-api 2.5 [provided]
flexjson 2.1
org.springframework.roo.annotations 1.1.5.RELEASE [provided]
spring-core 3.0.5.RELEASE
spring-test 3.0.5.RELEASE [test]
spring-context 3.0.5.RELEASE [test]
spring-aop 3.0.5.RELEASE
spring-aspects 3.0.5.RELEASE
spring-tx 3.0.5.RELEASE

To upgrade Spring, AspectJ and slf4j to the latest versions
(as of Dec 2011), I change the following lines in the pom.xml

<spring.version>3.0.5.RELEASE</spring.version>
<aspectj.version>1.6.11</aspectj.version>
<slf4j.version>1.6.1</slf4j.version>

into

<spring.version>3.0.6.RELEASE</spring.version>
<aspectj.version>1.6.12</aspectj.version>
<slf4j.version>1.6.4</slf4j.version>

Similarly I change JUnit to 4.10 and after saving the file the new
dependecies are fetched automatically.

Next, let’s add an ORM. In the Roo Shell:

persistence setup --provider DATANUCLEUS --database H2_IN_MEMORY

This step updated log4j.properties (just to make Datanucleus show only warnings), the pom.xml to add dependencies, applicationContext.xml to add the beans transactionManager and entityManagerFactory, and created persistence.xml – since I’m using an in memory database, no further configuration is needed, otherwise thats where to store the database connection configuration. The dependencies added are:

h2 1.3.155
persistence-api 1.0
datanucleus-core 1.1.5
datanucleus-jpa 1.1.5
datanucleus-rdbms 1.1.5
datanucleus-enhancer 1.1.4
jdo2-api 2.3-ec
hibernate-validator 4.1.0.Final
validation-api 1.0.0.GA
cglib-nodep 2.2, jta 1.1
spring-jdbc 3.0.6.RELEASE
spring-orm 3.0.6.RELEASE
commons-pool 1.5.4
commons-dbcp 1.3

This time the Problem view says “Project configuration is not up-to-date with pom.xml. Run project configuration update“. So I right click on the project, choose Maven -> Update Project configuration… -> OK

Let’s create a simple entity, from the Roo Shell:

entity --class ~.domain.Task
field string --fieldName description --notNull --sizeMin 3 --sizeMax 512
field boolean --fieldName completed --notNull

And create the scaffolding controller:

controller all --package org.obliquid.roosecurity1.controller

This step does a lot and transforms the application in a full featured web app adding web.xml, webmvc-config.xml, TaskController.java, ApplicationConversionServiceFactoryBeansecurity.java, images and stylesheets. Views are based on jspx with Apache Tiles and there is the basics for internationalization, although only English is installed by default.

At this point there are a couple of errors displayed in the problem view

ErrorCMDocument_load_exception=An error occurred while loading document {0} with publicId {1}

Funny that the placeholder variables don’t get substituted, anyway the error is in load-scripts.tagx and to solve it, I change the following lines:

<link rel="stylesheet" type="text/css" href="${tundra_url}"><!-- required for FF3 and Opera --></link>
<link rel="stylesheet" type="text/css" media="screen" href="${roo_css_url}"><!-- required for FF3 and Opera --></link>

into:

<link rel="stylesheet" type="text/css" href="${tundra_url}"></link>
<link rel="stylesheet" type="text/css" media="screen" href="${roo_css_url}"></link>

In this pass the dependencies added were:

spring-web 3.0.6.RELEASE
spring-webmvc 3.0.6.RELEASE
spring-webflow 3.0.6.RELEASE
spring-js-resources 2.2.1.RELEASE
commons-digester 2.0
commons-fileupload 1.2.1
jstl-api 1.2
jstl-impl 1.2
el-api 1.0
joda-time 1.6
jsp-api 2.1
commons-codec 1.4
tiles-core 2.2.1
tiles-jsp 2.2.1

To run the application, right click on the project, Run… -> Run On Server I choose Tomcat v7.0 -> Next -> Finish

Until now nearly everything worked and I’ve a basic web application, allowing me to add, modify and delete tasks. However, I’ve a buggy basic application, because trying to modify tasks, instead creates duplicates.

UPDATE: seems I’ve picked up a bad combination, others works, trying to understand, see post on stackoverflow.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">