读书人

Spring Roo(一)Install Spring Roo an

发布时间: 2012-08-29 08:40:14 作者: rapoo

Spring Roo(1)Install Spring Roo and Simple Sample
Spring Roo(1)Install Spring Roo and Simple Sample

1. install Spring Roo
I will first install roo shell on my system.
I download the roo from this URL http://s3.amazonaws.com/dist.springframework.org/release/ROO/spring-roo-1.2.0.RELEASE.zip

download the guide document from these URLs
http://spring-roo-repository.springsource.org/Getting_Started_with_Roo.pdf
http://static.springsource.org/spring-roo/reference/pdf/spring-roo-docs.pdf

Once I get this file spring-roo-1.2.0.RELEASE.zip, I unzip it and place it on my d driver.
D:\tool\spring-roo-1.2.0\bin
add this path to my system PATH.

I download the STS from this URL
http://download.springsource.com/release/STS/2.8.1/dist/e3.7/springsource-tool-suite-2.8.1.RELEASE-e3.7.1-win32-x86_64.zip

Unzip them and copy to tool directory. Click sts.exe to use it. Just like eclipse.

2. Create a sample application
>mkdir conference
>cd conference
>roo
>hint
>project --topLevelPackage com.sillycat.roo.conference --java 6 --projectName conference
--topLevelPackage is the package name
--java 6 is to defince the java version
--projectName is to define the project name
>hint
use hint to get some information from next steps and TAB button to get informations
>jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
--provider is one of the implementation of persistence
--database is one of the database

>hint
>entity jpa --class com.sillycat.roo.conference.models.Speaker --testAutomatically
>entity jpa --class com.sillycat.roo.conference.models.Talk --testAutomatically

>hint
>field string --fieldName firstname --class ~.models.Speaker --notNull
>field string --fieldName lastname --notNull
>field string --fieldName email --unique --notNull
>field string --fieldName organization
>field date --fieldName birthdate --type java.util.Date --past --notNull
>field number --type java.lang.Long --fieldName age --min 25 --max 60

add some fields to Talk class
>field string --fieldName title --class ~.models.Talk --notNull
>field string --fieldName description --notNull --sizeMax 4000

The relation ship between Speaker and Talk is ONE_TO_MANY. One speaker has a lot of talks.
>field set --fieldName talks --type ~.models.Talk --class ~.models.Speaker --cardinality ONE_TO_MANY
>field reference --fieldName speaker --type ~.models.Speaker --class ~.models.Talk --notNull

Try to geneate the web layer
>controller all --package ~.web

Add log4j to with command logging
>logging setup --level INFO --package ALL_SPRING

run the test case with commands
>perform tests
this command is equal to >mvn test

quit or q can quit the shell.

Start the web server tomcat with maven command
>mvn tomcat:run

We can access the application we created just now with this URL http://localhost:8080/conference

3. itergrate the project to my eclipse tool
>mvn eclipse:eclipse
And I import the project to my eclipse, and enable the maven dependency. Change the Java Compile Level to 1.5.

src/main/java/com.sillycat.roo.conference.models
We put all our models here. And all are marked as JPA POJO.

src/main/java/com.sillycat.roo.conference.web
We have all our controllers here, they are created by scaffold. Right now I do not know how to customized them.

src/main/resources/META-INF/spring
src/main/resources/META-INF
src/main/resources
We have all the confiration files here.

src/test/java/com.sillycat.roo.conference.models
SpeakerIntegrationTest
TalkIntegerationTest

src/main/webapp
All the web related configurations are here.


references:
http://www.ibm.com/developerworks/cn/opensource/os-springroo1/index.html?ca=drs-
http://www.ibm.com/developerworks/cn/opensource/os-springroo2/index.html?ca=drs-
http://static.springsource.org/spring-roo/reference/html/beginning.html
http://www.springsource.org/spring-roo
http://www.springsource.org/spring-roo#try
http://static.springsource.org/spring-roo/reference/html/index.html
http://zk1878.iteye.com/blog/1222330

读书人网 >编程

热点推荐