Introduce to Spring Roo


Study Hsueh

2014/03/16

Java RAD Study Group Meeting #1


Outline

  1. What is Spring Roo?
  2. Traditional Layered Web Architecture
  3. Basic commands
  4. Persistence Layer Configuration
  5. Domain Model
    1. Active Record Pattern
    2. Repository and Service  Pattern
  6. Service Layer
  7. Web Service Layer
  8. Presentation Layer

What is Spring Roo?









http://projects.spring.io/spring-roo/

Dec. 2009: 1.0.0.RELEASE GA
...
Jan. 2014: 1.2.5.RELEASE GA (Current)
Why does Java need RAD?
  •  Version Compatibility
  •  Complex Configuration
  •  Lots of different framework implementations
    • JPA: DataNucleus, EclipseLink, Hibernate, OpenJPA...
    • MVC: SpringMVC, Struts...
  • Dependency Management
  • ...
Let take a minute to think how many things
you need to setup up for a ORM framework?

Trad. Layered WEB Architecture


Basic Commands

  • Start Roo Shell
    $ roo

  • Hint
    roo> hint

  • Create Project
    roo> project --topLevelPackage org.phstudy


Roo Samples

  • Enter Roo Sample 
    $ cd $ROO_HOME/samples


  • The step to run Roo Sample
    $ mkdir bikeshop
    $ cd bikeshop
    $ roo script ../bikeshop.roo
    $ mvn package jetty:run


More info: http://docs.spring.io/spring-roo/reference/html/intro.html#intro-exploring-sample

Persistence Layer Configuration

  • Setup persistence layer configuration
    roo> persistence setup --provider {JPA_PROVIDER} --database {DATABASE_VENDOR}  --...


  • Setup MongoDB
    roo> mongo setup  --...


Domain Model

  • Create a JPA Active Record entity
    roo> entity jpa --class ~.model.Employee


    • Create a JPA traditional entity
      roo> entity jpa --class ~.model.Customer --activeRecord false








    Active Record Entity - Employee

    Trad. Entity - Customer


    Active Record Pattern (Roo)

    http://docs.spring.io/spring-roo/reference/html/base-layers.html http://www.martinfowler.com/eaaCatalog/activeRecord.html

    Service and Repository Pattern



    application layering

    Add fields to Entity

    • Focus on specific model
      roo> focus --class ~.model.Employee
      roo> focus --class ~.model.Customer


    • Add a Long type field to entity
      roo>   field number --fieldName age --type java.lang.Long


    • Add a String type field to entity
      roo> field  string --fieldName firstname

    app. architecture of Spring RoO


    Roo is based on AspectJ inter-type declarations (ITDs)



    http://docs.spring.io/spring-roo/reference/html/architecture.html

    Persistence Layer

    • Create Repository
      roo> repository jpa --interface ~.repository.CustomerRepository --entity ~.model.Customer


    • Active Record entity does NOT need this layer.

    Service Layer

    • Create single service
      roo> service type --interface ~.service.CustomerService --class ~.model.Customer


    • Create all services
      roo> service all --interfacePackage ~.service --classPackage ~.service.impl

    • This layer is optional.

    Web Service Layer

    • Create RESTful Web Service
      roo> json all --deepSerialize
      roo> web mvc json setup
      roo> web mvc json all --package ~.rest

    http://docs.spring.io/spring-roo/reference/html/base-json.html

    Presentation Layer

    • Setup spring mvc
      roo> web mvc setup
      roo> web mvc all --package ~.web

    http://docs.spring.io/spring-roo/reference/html/base-web.html

    Command index


    http://docs.spring.io/spring-roo/reference/html/command-index.html

    Mapping Relationships  Cheatsheet

    • One to One (owning side and inverse side)
      • Unidirection
      • Bidirection
    • One to Many (owning side, inverse side and jointable)
      • Unidirection
      • Bidirection
    • Many to Many (owning side, inverse side and jointable)
      • Unidirection
      • Bidirection

    One to One

    Books

    Getting Started with Roo

    Spring Roo 1.1 Cookbook

    Spring Roo in Action

    Spring Roo:Open-Source Rapid Application Development for Java

    Introduction to Spring Roo

    By study

    Introduction to Spring Roo

    • 1,172