Java Spring Roo: Difference between revisions

From Objectif Client Inc
Jump to navigation Jump to search
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Installation ==
== First Application ==
== Create application from Database ==
== Create application from Database ==
* Assuming Roo is installed
# Assuming Roo is installed
# Create project
# Validate with the roo addon manager if Mysql is already install org.springframework.roo.wrapping.mysql
# You may have to copy mysq.coonector.jar directly into the folder bundle in the roo installation directory
=== Install Mysql Driver ===
<pre>addon search mysql</pre>
<pre> addon install id 01</pre>
* If it goes wrong
<pre>osgi obr url add --url http://spring-roo-repository.springsource.org/repository.xml
osgi obr deploy --bundleSymbolicName org.springframework.roo.wrapping.mysql-jdbc </pre>
* If it goes very wrong
Copy mysql-connect.jar into bundle directory of the root installation repository
 
=== Create project ===
<pre>project --topLevelPackage com.objclt.roo.sample</pre>
<pre>project --topLevelPackage com.objclt.roo.sample</pre>
# Create Database Connection
 
=== Create Database Connection ===
* Create persistence.xml and database.properties
<pre>persistence setup --provider HIBERNATE --database MYSQL --databaseName databaseName --hostName hostname --userName username --password password</pre>
<pre>persistence setup --provider HIBERNATE --database MYSQL --databaseName databaseName --hostName hostname --userName username --password password</pre>
# Update database.properties
 
=== Validate database.properties ===
<pre>jdbc.driverClassName=com.mysql.jdbc.Driver
<pre>jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/Database_Name
jdbc.url=jdbc\:mysql\://localhost\:3306/Database_Name
jdbc.usernameDatabase_User
jdbc.usernameDatabase_User
jdbc.password=User_Password</pre>
jdbc.password=User_Password</pre>
# Replace create by validate inside persistence.xml to disable the auto database creation
 
=== Validate persistence.xml ===
* Si operation is not mandatory as is will be replaced when generating entities from database
* Replace create by validate inside persistence.xml to disable the auto database creation
<pre>
<pre>
"Before"
"Before"
Line 17: Line 39:
property name="hibernate.hbm2ddl.auto" value="validate"
property name="hibernate.hbm2ddl.auto" value="validate"
</pre>
</pre>
# Install Mysql Driver
 
<pre>addon search mysql</pre>
=== Test Database Connection ===
<pre> addon install id 01</pre>
* Will generate the dbrx.xml
# Test Database Connection
<pre>database introspect --schema DatabaseSchema</pre>
<pre>database introspect --schema DatabaseSchema</pre>
=== Reverse engineering of the database ===
Create Java Entity and AspectJ source
<pre>database reverse engineer --schema DataBaseShema --package com.objclt.roo.sample</pre>
=== Perform Junit Integration ===
<pre> test integration </pre>
===Configure Web presentation Layer===
<pre>web mvc setup</pre>
=== Generate Controller ===
<pre>web mvc all --package ~.web</pre>
=== Setup Security ===
* Create applicationContext-security.xml
<pre>security setup</pre>
==== Several Level of security ====
# Security by views Inside the applicationContext-seciruty.xml
<pre>
<intercept-url pattern="/users/**" method="DELETE" access="hasRole('ROLE_ADMIN')"
<intercept-url pattern="/roles/**" access="hasAnyRole('Administrator','role_display')" />
<intercept-url pattern="/roleslist/**" method="GET" access="isAuthenticated()"
<intercept-url pattern="/**" access="permitAll"
</pre>
# Inside a JSP page
<pre>
xmlns:sec="http://www.springframework.org/security/tags
<sec:authorize ifAllGranted="ROLE_ADMIN">
</sec:authorize>
<sec:authorize ifAnyGranted="ROLE_ADMIN, ROLE_USER">
</sec:authorize>
<sec:authorize ifNotGranted="ROLE_EXCLUDE">
</sec:authorize>
</pre>
# Inside the java controller file
<pre>@RooWebScaffold(path = "processeses", formBackingObject = Processes.class,delete=false,update=false)</pre>
=== Email Setup ===
* Create email.properties
<pre>email sender setup --hostServer smtp.gmail.com --username YourEmailAddress --password YourPassword --port 587 --protocol SMTP</pre>
=== Add Finder Search ===
* Create finder for Entity : Concepts
<pre>finder add --class ~.model.Concepts</pre>
* List
<pre>finder list</pre>
===Internationalization===
* Create a message file per language messages_es.properties inside i18n folder
* Create a flag es.png inside images
* Update views/footer.jspx to add the new language
<pre>web mvc install language --code es</pre>
=== Integration into eclipse ===
<pre>perform eclipse</pre>

Latest revision as of 02:57, 2 December 2014

Installation

First Application

Create application from Database

  1. Assuming Roo is installed
  2. Validate with the roo addon manager if Mysql is already install org.springframework.roo.wrapping.mysql
  3. You may have to copy mysq.coonector.jar directly into the folder bundle in the roo installation directory

Install Mysql Driver

addon search mysql
 addon install id 01
  • If it goes wrong
osgi obr url add --url http://spring-roo-repository.springsource.org/repository.xml
osgi obr deploy --bundleSymbolicName org.springframework.roo.wrapping.mysql-jdbc 
  • If it goes very wrong

Copy mysql-connect.jar into bundle directory of the root installation repository

Create project

project --topLevelPackage com.objclt.roo.sample

Create Database Connection

  • Create persistence.xml and database.properties
persistence setup --provider HIBERNATE --database MYSQL --databaseName databaseName --hostName hostname --userName username --password password

Validate database.properties

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/Database_Name
jdbc.usernameDatabase_User
jdbc.password=User_Password

Validate persistence.xml

  • Si operation is not mandatory as is will be replaced when generating entities from database
  • Replace create by validate inside persistence.xml to disable the auto database creation
"Before"
property name="hibernate.hbm2ddl.auto" value="create"
"After"
property name="hibernate.hbm2ddl.auto" value="validate"

Test Database Connection

  • Will generate the dbrx.xml
database introspect --schema DatabaseSchema

Reverse engineering of the database

Create Java Entity and AspectJ source

database reverse engineer --schema DataBaseShema --package com.objclt.roo.sample

Perform Junit Integration

 test integration 

Configure Web presentation Layer

web mvc setup

Generate Controller

web mvc all --package ~.web

Setup Security

  • Create applicationContext-security.xml
security setup

Several Level of security

  1. Security by views Inside the applicationContext-seciruty.xml
 <intercept-url pattern="/users/**" method="DELETE" access="hasRole('ROLE_ADMIN')"
 <intercept-url pattern="/roles/**" access="hasAnyRole('Administrator','role_display')" />
 <intercept-url pattern="/roleslist/**" method="GET" access="isAuthenticated()"
 <intercept-url pattern="/**" access="permitAll"
  1. Inside a JSP page
 
xmlns:sec="http://www.springframework.org/security/tags
<sec:authorize ifAllGranted="ROLE_ADMIN">
</sec:authorize>
<sec:authorize ifAnyGranted="ROLE_ADMIN, ROLE_USER">
</sec:authorize>
<sec:authorize ifNotGranted="ROLE_EXCLUDE">
</sec:authorize>
  1. Inside the java controller file
@RooWebScaffold(path = "processeses", formBackingObject = Processes.class,delete=false,update=false)

Email Setup

  • Create email.properties
email sender setup --hostServer smtp.gmail.com --username YourEmailAddress --password YourPassword --port 587 --protocol SMTP

Add Finder Search

  • Create finder for Entity : Concepts
finder add --class ~.model.Concepts
  • List
finder list

Internationalization

  • Create a message file per language messages_es.properties inside i18n folder
  • Create a flag es.png inside images
  • Update views/footer.jspx to add the new language
web mvc install language --code es

Integration into eclipse

perform eclipse