歡迎您光臨本站 註冊首頁

Spring Roo 第一次親密接觸

←手機掃碼閱讀     火星人 @ 2014-03-10 , reply:0
在本次的 SpringONE Europe 會議上,SpringSource 可以說是動作連連.
1. 發布新的 Spring 框架補丁版本 .
2. 發布新的 Spring 家族產品 Spring Roo .
3. 並且宣布 Spring Tool Suite 將免費提供給開發人員使用.
4. SpringSource 收購 Hyperic .

Spring Roo 是一種 Spring 開發的輔助工具,當你感嘆 Ruby on Rails,CakePHP,Seam Gen時,或許應該嘗試一下Spring Roo.
Spring 官方博客的 Spring Roo 介紹 .

下載 Spring Roo ,當前最新版本是 1.0 Alpha 2.

解壓至硬碟,設置環境變數 ROO_HOME ,指向 roo 所在的目錄.並將 $ROO_HOME/bin 添加到系統的 Path 中.

在Linux 你可以寫入當前用戶的 .bashrc 文件.

export ROO_HOME=/home/hantsy/libs/java/roo-1.0.0.A2
export PATH=$PATH:$ROO_HOME/bin

執行 source ~/.bashrc 讓它立即生效.

執行 roo.sh ,你可以進入 Spring Roo 命令行操作界面.

[[email protected] samples]$ ../bin/roo.sh
____ ____ ____
/ __ / __ / __
/ /_/ / / / / / / /
/ _, _/ /_/ / /_/ /
/_/ |_|____/____/


Welcome to Spring ROO. For assistance press TAB or type "hint" then hit ENTER.


roo>

你可以輸入 help,查看幫助信息.

roo> help
* */ - End of block comment
* /* - Start of block comment
* // - Inline comment markers
* ; - Inline comment markers
* create project - Creates a new project
* database properties - Shows database configuration details
* database remove - Removes a particular database property
* database set - Changes a particular database property
* date - Displays the local date and time
* development mode - Switches the system into development mode (greater diagnostic information)
* exit - Exits the shell
* help - Shows system help
* hint - Provides step-by-step hints and context-sensitive guidance
* metadata for id - Shows detailed information about the metadata item
* metadata for type - Shows detailed metadata for the indicated type
* metadata summary - Shows statistics on the metadata system
* metadata trace - Traces metadata event delivery notifications (0=none, 1=some, 2=all)
* new controller manual - Create a new manual Controller (ie where you write the methods)
* new dod - Creates a new data on demand for the specified entity
* new integration test - Creates a new data on demand for the specified entity
* property file details - Shows the details of a particular properties file
* property file remove - Removes a particular properties file property
* property file set - Changes a particular properties file property


* props - Shows the shell's properties
* quit - Exits the shell
* script - Parses the specified resource file and executes its commands
* version - Displays shell version

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

Spring Roo 提供大量的代碼生成的功能,包括就最基本的 CRUD 操作,還可以設置資料庫,日誌log4j 級別,Spring security 等.

Spring roo 中提供兩個實例,他們是兩個 .roo 文件,包括一些創建項目文件的腳本.
進入 sample 目錄.
roo>script vote.roo
create project -topLevelPackage com.springsource.vote
Created /home/hantsy/libs/java/roo-1.0.0.A2/samples/pom.xml
Created SRC_MAIN_JAVA
Created SRC_MAIN_RESOURCES
Created SRC_TEST_JAVA
Created SRC_TEST_RESOURCES
Created SRC_MAIN_WEBAPP
Created SRC_MAIN_RESOURCES/applicationContext.xml
Created SRC_MAIN_WEBAPP/WEB-INF
Created SRC_MAIN_WEBAPP/WEB-INF/vote-servlet.xml
Created SRC_MAIN_WEBAPP/WEB-INF/web.xml
Created SRC_MAIN_WEBAPP/index.jsp

install jpa -provider HIBERNATE -database HYPERSONIC_PERSISTENT
Created SRC_MAIN_RESOURCES/META-INF
Created SRC_MAIN_RESOURCES/META-INF/persistence.xml
Created SRC_MAIN_RESOURCES/database.properties
Managed SRC_MAIN_RESOURCES/applicationContext.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml
Managed ROOT/pom.xml

new persistent class jpa -name ~.domain.Choice -testAutomatically
Created SRC_MAIN_JAVA/com/springsource/vote/domain
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice.java
Created SRC_TEST_JAVA/com/springsource/vote/domain
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceDataOnDemand.java
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceIntegrationTest.java
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_Plural.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_Entity.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_ToString.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_Configurable.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceIntegrationTest_Roo_IntegrationTest.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceDataOnDemand_Roo_Configurable.aj
add field string namingChoice -notNull -sizeMin 1 -sizeMax 30
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Choice.java
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_JavaBean.aj
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_ToString.aj
Managed SRC_TEST_JAVA/com/springsource/vote/domain/ChoiceDataOnDemand_Roo_DataOnDemand.aj


add field string description -sizeMax 80
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Choice.java
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_JavaBean.aj
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Choice_Roo_ToString.aj
new controller automatic ~.web.ChoiceController
Created SRC_MAIN_JAVA/com/springsource/vote/web
Created SRC_MAIN_JAVA/com/springsource/vote/web/ChoiceController.java
Created SRC_MAIN_JAVA/com/springsource/vote/web/ChoiceController_Roo_Controller.aj
Created SRC_MAIN_WEBAPP/images
Created SRC_MAIN_WEBAPP/images/banner-graphic.png
Created SRC_MAIN_WEBAPP/images/springsource-logo.png
Created SRC_MAIN_WEBAPP/images/list.png
Created SRC_MAIN_WEBAPP/images/show.png
Created SRC_MAIN_WEBAPP/images/create.png
Created SRC_MAIN_WEBAPP/images/update.png
Created SRC_MAIN_WEBAPP/images/delete.png
Created SRC_MAIN_WEBAPP/styles
Created SRC_MAIN_WEBAPP/styles/roo.css
Created SRC_MAIN_WEBAPP/WEB-INF/jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/header.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/footer.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/includes.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/dataAccessFailure.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/uncaughtException.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/choice
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/choice/list.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/choice/show.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/choice/create.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/choice/update.jsp
Managed SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp

new persistent class jpa -name Vote -testAutomatically
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote.java
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteDataOnDemand.java
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteIntegrationTest.java
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_Plural.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_Entity.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_ToString.aj
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_Configurable.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteDataOnDemand_Roo_Configurable.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteDataOnDemand_Roo_DataOnDemand.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteIntegrationTest_Roo_Configurable.aj
Created SRC_TEST_JAVA/com/springsource/vote/domain/VoteIntegrationTest_Roo_IntegrationTest.aj
add field reference jpa choice -type Choice
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote.java
Created SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_JavaBean.aj
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_ToString.aj
add field string ip -notNull -sizeMin 7 -sizeMax 15
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote.java
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_JavaBean.aj


Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_ToString.aj
Managed SRC_TEST_JAVA/com/springsource/vote/domain/VoteDataOnDemand_Roo_DataOnDemand.aj
add field date jpa registered -type java.util.Date -notNull -past
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote.java
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_JavaBean.aj
Managed SRC_MAIN_JAVA/com/springsource/vote/domain/Vote_Roo_ToString.aj
Managed SRC_TEST_JAVA/com/springsource/vote/domain/VoteDataOnDemand_Roo_DataOnDemand.aj
new controller automatic ~.web.VoteController
Created SRC_MAIN_JAVA/com/springsource/vote/web/VoteController.java
Created SRC_MAIN_JAVA/com/springsource/vote/domain/ChoiceEditor.java
Created SRC_MAIN_JAVA/com/springsource/vote/web/VoteController_Roo_Controller.aj
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/vote
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/vote/list.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/vote/show.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/vote/create.jsp
Created SRC_MAIN_WEBAPP/WEB-INF/jsp/vote/update.jsp
Managed SRC_MAIN_WEBAPP/WEB-INF/jsp/menu.jsp
Created SRC_MAIN_JAVA/com/springsource/vote/domain/ChoiceEditor_Roo_Editor.aj

new controller manual ~.web.PublicVoteController
Created SRC_MAIN_JAVA/com/springsource/vote/web/PublicVoteController.java

configure logging -level DEBUG -package WEB
Created SRC_MAIN_RESOURCES/log4j.properties
Managed SRC_MAIN_WEBAPP/WEB-INF/web.xml

install security
Managed ROOT/pom.xml
Created SRC_MAIN_RESOURCES/applicationContext-security.xml
Created SRC_MAIN_WEBAPP/login.jsp
Managed SRC_MAIN_WEBAPP/WEB-INF/web.xml

list finders for -class com.springsource.vote.domain.Vote -depth 2 -filter reg,betw,IpEq
findVotesByIpEqualsAndRegisteredBetween(String ip, Date minRegistered, Date maxRegistered)
findVotesByIpEqualsOrRegisteredBetween(String ip, Date minRegistered, Date maxRegistered)
findVotesByRegisteredBetweenAndIpEquals(Date minRegistered, Date maxRegistered, String ip)
findVotesByRegisteredBetweenOrIpEquals(Date minRegistered, Date maxRegistered, String ip)
roo>

輸入 quit 退出交互界面.
你會發現 Spring Roo 生成的是一個 Maven 項目,你可以將它導入 Eclipse 中,你需要安裝 m2clipseAJDT 插件.

在項目的中目錄中執行 mvn eclipse:eclipse ,maven 會幫你生成一個 eclipse 項目.
現在你可以將它導入到 eclipse 中.

它是一個 web 項目,可以把它部署到伺服器上運行.



[火星人 ] Spring Roo 第一次親密接觸已經有631次圍觀

http://coctec.com/docs/java/show-post-61603.html