Skip to content

Instantly share code, notes, and snippets.

@davizalpe
Created January 29, 2017 18:45
Show Gist options
  • Save davizalpe/e0a652aebee7515deaecfc6632321b5c to your computer and use it in GitHub Desktop.
Save davizalpe/e0a652aebee7515deaecfc6632321b5c to your computer and use it in GitHub Desktop.
Howto Spring Roo

Spring Roo project

====================

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

  1. Install

wget http://spring-roo-repository.springsource.org.s3.amazonaws.com/release/ROO/spring-roo-1.3.1.RELEASE.zip unzip spring-roo-1.3.1.RELEASE.zip echo "export ROO_HOME=$HOME/spring-roo-1.3.1.RELEASE" >> ~/.bashrc echo "export ROO_OPTS="-Droo.bright=true"" >> ~/.bashrc echo "export PATH=$ROO_HOME/bin:$PATH" >> ~/.bashrc

  1. Configuration

$ roo.sh roo> hint roo> project --topLevelPackage com.coincelt.base

roo> hint roo> jpa setup --provider HIBERNATE --database MYSQL or roo> jpa setup --provider HIBERNATE --database MYSQL --databaseName coincelt --userName user --password password --hostName localhost

Edit details: src/main/resources/META-INF/spring/database.properties

  1. Create entities

roo> hint roo> ent[tab] roo> help entity jpa Keyword: entity jpa Description: Creates a new JPA persistent entity in SRC_MAIN_JAVA Keyword: class Help: Name of the entity to create Mandatory: true Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: extends Help: The superclass (defaults to java.lang.Object) Mandatory: false Default if specified: 'NULL' Default if unspecified: 'java.lang.Object'

Keyword: implements Help: The interface to implement Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: abstract Help: Whether the generated class should be marked as abstract Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: testAutomatically Help: Create automatic integration tests for this entity Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: table Help: The JPA table name to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: schema Help: The JPA table schema name to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: catalog Help: The JPA table catalog name to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: identifierField Help: The JPA identifier field name to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: identifierColumn Help: The JPA identifier field column to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: identifierType Help: The data type that will be used for the JPA identifier field (defaults to java.lang.Long) Mandatory: false Default if specified: 'java.lang.Long' Default if unspecified: 'java.lang.Long'

Keyword: versionField Help: The JPA version field name to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: versionColumn Help: The JPA version field column to use for this entity Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: versionType Help: The data type that will be used for the JPA version field (defaults to java.lang.Integer) Mandatory: false Default if specified: 'NULL' Default if unspecified: 'java.lang.Integer'

Keyword: inheritanceType Help: The JPA @Inheritance value (apply to base class) Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: mappedSuperclass Help: Apply @MappedSuperclass for this entity Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: equals Help: Whether the generated class should implement equals and hashCode methods Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: serializable Help: Whether the generated class should implement java.io.Serializable Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: persistenceUnit Help: The persistence unit name to be used in the persistence.xml file Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: transactionManager Help: The transaction manager name Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: permitReservedWords Help: Indicates whether reserved words are ignored by Roo Mandatory: false Default if specified: 'true' Default if unspecified: 'false'

Keyword: entityName Help: The name used to refer to the entity in queries Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: sequenceName Help: The name of the sequence for incrementing sequence-driven primary keys Mandatory: false Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: activeRecord Help: Generate CRUD active record methods for this entity Mandatory: false Default if specified: 'true' Default if unspecified: 'true'

  • entity jpa - Creates a new JPA persistent entity in SRC_MAIN_JAVA

Create entity

roo> entity jpa --class ~.domain.userprofile.UserProfile --testAutomatically or roo> entity jpa --class ~.domain.userprofile.UserProfile --testAutomatically --table UserProfile --identifierField userProfileId --versionType java.lang.Long --equals --serializable

Create fields

roo> hint roo> field

In other terminal export command-line fields creation using reversing MySQL schema

./scaffolder_roo_reverse_sql.sh database table

Spring Roo shell

roo> field number --fieldName userProfileId --notNull --type java.lang.Long roo> field string --fieldName email --notNull --sizeMax 90 --unique roo> field boolean --fieldName enabled --value 0 --primitive roo> field date --fieldName created --type java.util.Date roo> field number --fieldName version --type long --primitive roo> field reference --fieldName entityToReference --type ~.domain.EntityRefered

Focus on another entity

roo> quit roo> focus --class ~.domain.Entity

List finders

roo> finder list

Create finders

roo> finder add --finderName findUserProfilesByEmailEquals roo> finder add --finderName findUserProfilesByToken_expiredLessThanEquals roo> finder add --finderName findUserProfilesByTokenEquals

  1. Create a Spring MVC

~.domain.userprofile.UserProfile roo> hint At this stage of the project, you have a few options:

  • List all hint topics via 'hint topics'
  • Create more fields with 'hint fields'
  • Create more entities with 'hint entities'
  • Create a web controller with 'hint web mvc'
  • Create dynamic finders with 'hint finders'
  • Setup your logging levels via 'hint logging'
  • Run tests via Maven (type 'perform tests')
  • Build a deployment artifact (type 'perform package')
  • Learn about Eclipse integration by typing 'hint eclipse'
  • Add support for Google Web Toolkit via 'hint gwt'
  • Discover all Roo commands by typing 'help'

~.domain.userprofile.UserProfile roo> hint topics The following hints are available to help you use Roo:

general, start, persistence, entities, fields, relationships, web mvc, finders, eclipse, logging, gwt

Just type 'hint topic_name' (without quotes) to view a specific hint.

roo> hint web mvc

Create all fields from Spring MVC

roo> web mvc setup roo> web mvc[tab] web mvc all web mvc controller web mvc embed web mvc finder web mvc install web mvc json
web mvc language web mvc scaffold web mvc update web mvc view

Create all controller

roo> web mvc all --package ~.web

Add i18n

roo> web mvc language --code es roo> web mvc language --code it roo> web mvc language --code de roo> web mvc install language es

Install language

Indicates to automatically trust all keys encountered until the command is invoked again

roo> pgp automatic trust roo> addon search language roo> addon install id 03 roo> web mvc language --code fr

roo> web mvc install language

Create static views

roo> web mvc view --path / --viewName about --title "About Us"

  1. Add test roo> selenium test --controller ~.web.TimerController

  2. Add security roo> security setup

  3. Perform test roo> perform tests

  4. Enable GWT

roo> download accept terms of use roo> web gwt setup roo> web gwt all --proxyPackage --requestPackage roo> web gwt gae update roo> web gwt proxy all --package roo> web gwt scaffold --proxyPackage --requestPackage --type

  1. Add finders to the view

roo> help web mvc finder add Keyword: web mvc finder add Description: Adds @RooWebFinder annotation to MVC controller type Keyword: formBackingType Help: The finder-enabled type Mandatory: true Default if specified: 'NULL' Default if unspecified: 'NULL'

Keyword: class Help: The controller java type to apply this annotation to Mandatory: false Default if specified: 'NULL' Default if unspecified: '*'

  • web mvc finder add - Adds @RooWebFinder annotation to MVC controller type

** Type 'hint' (without the quotes) and hit ENTER for step-by-step guidance **

roo> web mvc finder add --class ~.web.UserProfileController --formBackingType ~.domain.userprofile.UserProfile

todos los controladores

roo> web mvc finder all

  1. Create JSON REST

roo> json all roo> web mvn json all roo> web mvc json setup

  1. Instalar addons

roo> pgp automatic trust

roo> addon search ID T R DESCRIPTION ------------------------------------------------------------- 01 Y Y 2.3.0.0001 This bundle wraps the standard Maven artifact: protobuf-java-2.3.0-lite. 02 Y - 0.3.0.RELEASE Addon for Spring Roo to provide generic DAO and query methods based on Hades. 03 Y Y 0.9.94.0001 This bundle wraps the standard Maven artifact: jline-0.9.94.S2-A (S2-A is a private patched version; see ROO-350 for... 04 - - 1.1.6 Addons that adds Content Negotiating View Resolver configuration to your application context: MVC multiple representations By default... ...(output truncated for reference guide inclusion)...

Info de un addon

roo> addon info id --searchResult 01

Instalar in addon

roo> addon install id --searchResultId 02

Eliminar addon

roo> addon remove --bundleSymbolicName de.saxsys.roo.equals.addon

  1. Reversing database schema

roo> database introspect --schema no-schema-required Located add-on that may offer this JDBC driver 1 found, sorted by rank; T = trusted developer; R = Roo 1.1 compatible ID T R DESCRIPTION ------------------------------------------------------------- 01 Y Y 5.1.13.0001 #jdbcdriver driverclass:com.mysql.jdbc.Driver. This...

[HINT] use 'addon info id --searchResultId ..' to see details about a search result [HINT] use 'addon install id --searchResultId ..' to install a specific search result, or [HINT] use 'addon install bundle --bundleSymbolicName TAB' to install a specific add-on version JDBC driver not available for 'com.mysql.jdbc.Driver'

roo> addon install id --searchResultId 01

roo> database introspect --schema no-schema-required roo> database introspect --schema --file --enableViews roo> database reverse engineer --schema --package --activeRecord --repository --service --testAutomatically --enableViews --includeTables --excludeTables --includeNonPortableAttributes --disableVersionFields --disableGeneratedIdentifiers

Reverse BBDD excluding some tables

roo> database reverse engineer --schema database --package ~.domain --excludeTables "foo* PingTable"

Add several BBDD

roo> database reverse engineer --schema "schema1 schema2 schema3" --package ~.domain

osgi start --url http://spring-roo-repository.springsource.org/release/org/springframework/roo/wrapping/org.springframework.roo.wrapping.connector/1.0.0010/org.springframework.roo.wrapping.connector-1.0.0010.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment