Introduce to Spring Roo
Study Hsueh
2014/03/16
Java RAD Study Group Meeting #1
Outline
- What is Spring Roo?
- Traditional Layered Web Architecture
- Basic commands
- Persistence Layer Configuration
- Domain Model
- Active Record Pattern
- Repository and Service Pattern
- Service Layer
- Web Service Layer
- Presentation Layer
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
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

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 String type field to entity
roo> field string --fieldName firstname
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
Mapping Relationships Cheatsheet
- One to One (owning side and inverse side)
- One to Many (owning side, inverse side and jointable)
- Many to Many (owning side, inverse side and jointable)