By Subham Aggarwal | 7/17/2017 | General |Beginners

Spring Roo

Spring Roo

Spring Roo is a lightweight developer tool that makes it fast and easy to deliver instant results. Best of all, you code 100% in Java and get to reuse all your existing Java knowledge, skills and experience.

Spring Roo differs from other productivity tools by focusing on:

  • Rapid results
  • 100% develop in Java
  • Being easy-to-use
  • Fast and simple to remove
  • Totally compromise free
  • Active, helpful community
  • Comprehensive technology integrations
  • Extension points via Roo add-ons
  • Spring-certified architecture

Spring Roo is a Rapid Application Development (RAD) tool that aims to deliver fast, and instant results focused on Spring web applications and newer Spring technologies. It allows us to generate boilerplate code and project structure for Spring applications with simple to use commands.

Installation

Apart from Java SDK 8 and STS, download and install Spring Roo.

Once we download and install Java JDK and STS, we need to unzip Spring Roo and add it to the system path.

Let’s create the ROO_HOME environment variable and add %ROO_HOME%\bin to the path.

To verify that Roo is installed correctly, we can open the command line and execute following commands:

mkdir discover
cd discover
roo quit

 

After a few seconds we will see:

___ _ __  _ __(_)_ __   __ _   _ __ ___   ___
/ __| '_ \| '__| | '_ \ / _` | | '__/ _ \ / _ \
\__ \ |_) | |  | | | | | (_| | | | | (_) | (_) |
|___/ .__/|_|  |_|_| |_|\__, | |_|  \___/ \___/
   |_|              |___/       2.0.0.RC1

Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.

 

Roo is installed, and it is working. Please note that Spring Roo version will vary and the steps and instructions may depend on the actual version used.

Now, follow the set of commands below to get started very very quickly:

mkdir hello
cd hello
roo.sh
roo> project setup --topLevelPackage com.foo
roo> jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
roo> entity jpa --class ~.domain.Movie
roo> field string --fieldName name --notNull
roo> repository jpa --all
roo> service --all
roo> web mvc setup
roo> web mvc view setup --type THYMELEAF
roo> web mvc controller --all --responseType THYMELEAF
roo> web mvc controller --all --pathPrefix /api
roo> quit
mvn spring-boot:run

 

We are now ready to run our application. However, let’s step back through the commands to see what we have done.

First, we created a new JPA persistent entity in the src/main/java folder. Next, we created a String field in Movie class, gave them a name and set it to be not null.

After that, we generated a Spring Data repository for the specified entity and created a new service interface.

In the end, we included Spring MVC configuration, installed Thymeleaf and created a new controller that manages our entity. Because we have passed Thymeleaf as the response type, the generated methods and views will reflect this.

More about Spring Roo

When we open Movie.java class file, we’ll notice that the class is annotated with @Roo annotations. These were added by Roo Shell and are used to control and customize the content of AspectJ inter-type declaration (ITD) files. We can view the files in Package Explorer in STS by unselecting “Hide generated Spring Roo ITDs” filter in the View Menu, or we can open the files directly from the file system.

Roo annotations have SOURCE retention policy. This means the annotations won’t be present in compiled class bytecode, and there won’t be any dependency to Roo in deployed applications.

Another, obviously missing part in the Movie.java class are getters and setters. These are stored in separate AspectJ ITD files, as already mentioned. Roo will actively maintain this boilerplate code for us. Therefore, changes to fields in any class will be automatically reflected in AspectJ ITDs as Roo is “monitoring” all changes—either done via Roo Shell or directly by a developer in IDE.

Roo will take care of the repetitive code like toString() or equals() methods too.

Moreover, the framework can be easily removed from the project, avoiding vendor lock-in, by removing annotations and pushing-in AspectJ ITD to standard java code.

What Roo is not?

Now that we’ve covered what Roo is and can do, let's also clear up a few things it is NOT:

  • Roo is not a runtime. Roo is not involved with your project when it runs in production. You won't find any Roo JARs in your runtime classpath or Roo annotations compiled into your classes. This is actually a wonderful thing. It means you have no lock-in to worry about (you can remove Roo from your project in just a couple of minutes!).
  • Roo is not an IDE plugin. There is no requirement for a "Roo Eclipse plugin" or "Roo IntelliJ plugin". Roo works perfectly fine in its own operating system command window.
  • Roo is not an annotation processing library. There is a Java 6 feature known as the annotation processing API. Roo does not use this API. This allows Roo to work with Java 5, and also gives us access to a much more sophisticated and extensible internal model.

Spring Boot vs Spring Roo

Spring Roo is useful to generate and maintain source code and to avoid having to write tons of boilerplate code. It's really useful for CRUD web application and I think it does not gain anything by the use of Boot.

Spring Boot is a way to help you to boost the environment configuration phase and to let you start to use your app as soon as possible. As the Spring guys say:

Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

Spring Boot features:

  • Create stand-alone Spring applications
  • Embed Tomcat or Jetty directly (no need to deploy WAR files)
  • Provide opinionated 'starter' POMs to simplify your Maven configuration
  • Automatically configure Spring whenever possible
  • Provide production-ready features such as metrics, health checks and externalized configuration
  • Absolutely no code generation and no requirement for XML configuration

If you already have an established app, I can't see real advantages to use Boot (and in any case I didn't saw a "Boot powered" app in any real production environment yet), but if you want to use it anyway you can do it without problems, just take care of these:

  • Roo enrich your code through AspectJ, writing file aside by your source files, so these parts are transparent to tools like Boot
  • Roo generates configuration files also, and some of them are Spring configuration files. These configurations are the same domain of work of Boot, but Boot take the precedence and can ignore them (convention over configuration) so you need to pay attention to that, and redo with Boot, using convention, the same thing Roo had already done for you but is actually ignored at runtime.

For the rest, Boot integrates with Roo as with other already developed Spring app.

By Subham Aggarwal | 7/17/2017 | General

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Recent Stories

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
3220
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
User photo
3060
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
Show All
X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now