Spring Roo

Getting Started with Spring Roo

Spring, the Most Productive Way to Build Java Applications

Spring Roo, an open source software tool from SpringSource, is a dynamic, is a lightweight developer tool that makes it fast, easy and  rapid application development of Java. by enforcing correct coding practices and patterns and integrates with  Java technologies, including WebFlow,GWT,Spring MVC,Spring Security,JPA/hibernate and so on …

Pre-requisites

Before performing this project, you need to meet the following prerequisites:

  • Spring Roo needs to play a role during your development so you need a correctly configured development tool.
  • JDK1.6 or JDK1.7
  • Maven 3.2 or above
  • Internet Acces to download the required dependency.

You can working with Spring Tools Suite (STS).

In our Application we will use Eclispe Luna and Add Spring Tools.

 

Getting Started

First Step is to choose database and A JPA Provider

roo> jpa setup –database POSTGRES –provider HIBERNATE

roo> database properties set –key database.username –value ….

roo> database properties set –key database.password –value ….

database.password=….
database.url=jdbc\:postgresql\://localhost\:5432/mydb
database.username=…
database.driverClassName=org.postgresql.Driver

Spring Roo manage Maven dependency, create and synchornizez all the needed file.

Create Our First JPA entity in our case Product, Category.

We choose not use activeRecods pattern(optional) and to include automatic integration tests.

Create the Entity classes :

  • entity jpa –class org.project.domain.Product –activeRecord false –testAutomatically true
  • And add String field  to the entity with some restrictions not null , with min and max ..
  • field string –fieldName name –notNull –sizeMin 4 –sizeMax 16
  • field string –fieldName name –notNull true –sizeMin 4 –sizeMax 16
  • field number –type int –fieldName quantity
  • field number –type java.lang.Double –fieldName price –notNull
  • field date –type java.util.Date –fieldName dateOfCreation
  • entity jpa –class org.project.domain.Category –activeRecord false –testAutomatically true
  • field string –fieldName name –notNull true

Create the repository (DAO)

  • repository jpa –interface ~.dao.ProductDAO  –entity ~.domain.Product
  • repository jpa –interface ~.dao.CategoryDAO  –entit ~.domain.Category
  • focus –class ~.domain.Product
  • field reference –type ~.domain.Category –fieldName category –cardinality MANY_TO_ONE

Create the service

  • service type –interface org.project.service.CategoryService  –entity ~.dao.CategoryDAO
  • service type –interface org.project.service.CategoryService  –entity ~.dao.CategoryDAO

Create the Controller

  • web mvc setup
  • web mvc scaffold –class org.project.controller.ProductController –backingType ~.domain.Product
  • web mvc scaffold –class org.project.controller.CategoryController –backingType ~.domain.Category

Security

security setup

 

Leave a comment