不许说真话的博客 http://blog.sina.com.cn/wocnm
]
一、下载STS
下载安装后,运行出现dashboard,选择下方extensions,搜索grails,将看着有用的全部都装上。
目前装了 grails / grails IDE/groovy Compiler2.3 Feature/Groovy -eclipse Feature/JDT CORE
二、建立一个grails 项目,例如test
1、项目建立后,如果使用mysql数据库,将mysql目录下 Connector J 5.* 下的JAR文件,复制到test/lib下
2、修改test/grails-app/conf/DataSource.groovy:
dataSource {
pooled = true
jmxExport = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "******"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/devdb?useUnicode=true&characterEncoding=UTF-8"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=UTF-8"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/prodb?useUnicode=true&characterEncoding=UTF-8"
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
}
三个database分别用于开发、测试及发布。这样mysql配置就完成了
3、修改 test/grails-app/conf/BuildConfig.groovy:
加上 compile ":Shiro:1.2.1"
4、在sts的命令行(debug/run/run last/grails commond history)最后一个,打开命令行,
输入 : compile
在控制台一堆输出后, shiro插件就算安装完了
注1:2.3版本以后grails安装插件,无法用install命令行,只能修改BuildConfig.groovy,
可以用build/compile/runtime,三种方式,其实就是项目build时加载、 编译时加载以及运行时加载的区别。
具体插件列表和可用版本,可访问 http://repo.grails.org/grails/plugins/org/grails 来查询。
注2:shiro是安全框架,跟Spring Security 相比,更轻更易用。