Java and J2EE Tutorials, Jsp and Servlet Tutorials, Spring MVC, Solr, XML, JSON Examples, Hibernate & Struts 2 Hello World projects



Friday, 1 February 2013

Spring Roo simple hello world example in STS - What is spring roo ?

Today we are going to discuss about Spring Roo, in this blog we will come to know what spring roo is ? and how can we use it in a productive environment to achieve industry best practices. We are going to implement a simple spring mvc application using spring roo and come to know about automatic creation of domain, controller and views in our application.

Roo makes application development easy in a fundamental and sustainable improved way without compromising to productivity, engineering integrity and flexibility.

It means that spring roo makes you implement your business ideas implementation fast and easy. The most interesting part of spring roo is that you are not bound to accept the generated code as it is, rather you can change the code at any point of time to make it fit according to you needs.

What is Spring Roo ?
Spring roo is simply a tool that sits there in the background and handles the things that you do not want to worry about. Using Roo you can focus on your domain model and business need and everything else will be handled by spring itself.

There is no roo.jar dependency to add in your application explicitly, so it is purely a tool that helps you things going with a less effort.

Spring Roo simply makes the developer's work easy without getting in their way. Roo provides tools to fetch the application out of it completely and after that you are free with your application to use any coding patter you choose or any technology you want to add to your application.

Spring Roo in STS
If you are using STS you do not need to add something else, everything is already added to it for you to start working with roo. STS has almost every plugin installed in it that you would typically need and you can add more plugins to it as per your need. STS is based on Eclipse IDE with a better Spring MVC development environment.



Lets start with some demo application with STS IDE and let the real magic begin.The first thing we will do is to invoke a wizard and start a spring roo application as shown in picture :

spring-roo-hello-world


Click finish and it will create a project ready for us, a project in typical maven style having a pom.xml in it.

spring-roo-hello-world

Now the wondeful thing about roo is that it will guides you through the project creation process, every time. If you do not know what to do, just write hint in roo shell and you will get things to choose like the screen below.

Adding database and JPA details
Choose your db type from a list of all available databases and add JPA tool like hibernate if you want to   add one :

spring-roo-hello-world


Provider means the jpa implementation that you want to use, for now lets choose hibernate and click ok. Roo will add all required dependencies according to your db and Jpa.

spring-roo-hello-world


Adding Domain Entity to your database
Write entity-jpa and Ctrl+Space, now choose the package and domain name that you want to add:
Use Ctrl+Space every time to get a autocomplete for your commands. 

spring-roo-hello-world

Roo will add all folders and details for your domain classes as shown in the figure below:

spring-roo-hello-world

As the figure shown below indicates that roo will create a domain class for you automatically in your project structure:

spring-roo-hello-world

Adding fields to Database Entity
Don't know what to do next ? No worries ! Just ask roo again what to do now, simply write hint again and hit enter. Its suggesting to add some fields to your database table, simple write fields and Ctrl+space. Choose a datatype for your field from list of parameters and give a name for field.


spring-roo-hello-world

Every time you want to see available parameters or command list hit Ctrl+Space and choose one from suggesting list.


Adding Controllers
Write controller and press Ctrl+Space, now select your root package, add a sub package and controller name that you want to add, roo will add all files and packages to your project as shown in the figure below :

spring-roo-hello-world

Adding Views
Views are automatically added to your project structure according to domain and controller you have added so far  as shown in th figure below

spring-roo-hello-world

Note that the generated code for domains, controller and views can be edited manually at any point of time without any interrupt.

This way with roo we can add all files to our project on the fly and these files can be edited and more code can be added later on to make all these stuff working according to your business need.

BigData Technologies and NoSql - What is Apache Hadoop, MapReduce, HDFS, Hive and Pig
Introduction to Apache Solr 4.0 with Apache Tomcat
Introduction to Servlets (Part 1 of 3)
MVC Pattern and Frameworks (model, view and controller)
WebSocket with Java (Simple HelloWorld ChatApp using websocket and atmosphere in java)










Thanks for reading !
Being Java Guys Team


2 comments:

  1. i am getting following error

    entity jpa --class com.test.users
    java.lang.IllegalStateException: Failed to convert 'com.test.users' to type JavaType for option 'class'

    ReplyDelete
  2. you have to write for example:

    entity jpa --class com.test.users.domain.Users

    ReplyDelete

Like Us on Facebook


Like Us On Google+



Contact

Email: neel4soft@gmail.com
Skype: neel4soft