在本次的 会议上, 可以说是动作连连。
1. 发布新的 。
2. 发布新的 Spring 家族产品 。
3. 并且宣布 将免费提供给开发人员使用。
4. 。
Spring Roo 是一种 Spring 开发的辅助工具,当你感叹 Ruby on Rails,CakePHP,Seam Gen时,或许应该尝试一下Spring Roo。
Spring 官方博客的
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 命令行操作界面。
[hantsy@localhost 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 中,你需要安装 和 插件。
在项目的中目录中执行 mvn eclipse:eclipse ,maven 会帮你生成一个 eclipse 项目。
现在你可以将它导入到 eclipse 中。
它是一个 web 项目,可以把它部署到服务器上运行。