2019独角兽企业重金招聘Python工程师标准>>>
1.Grails 开发的时候要求JDK 6 ,但是可以部署到JDK5环境(BuildConfig.groovy)
grails.project.source.level = "1.5"
grails.project.target.level = "1.5"
2.指定Servlet 版本(BuildConfig.groovy)
grails.servlet.version = "3.0"
3.配置 root logger (Config.groovy)
log4j = {
root {
info()
}
…
}
4.配置全局failOnError (Config.groovy)
grails.gorm.failOnError=true
5.package 级别 failOnError (Config.groovy)
grails.gorm.failOnError = ['com.companyname.somepackage','com.companyname.someotherpackage']
6.环境检测
import grails.util.Environment
...
switch (Environment.current) {
case Environment.DEVELOPMENT:
configureForDevelopment()
break
case Environment.PRODUCTION:
configureForProduction()
break
}
Environment.executeForCurrentEnvironment {
production {
// do something in production
}
development {
// do something only in development
}
}
7.启动时环境检测 (BootStrap.groovy)
def init = { ServletContext ctx ->
environments {
production {
ctx.setAttribute("env", "prod")
}
development {
ctx.setAttribute("env", "dev")
}
}
ctx.setAttribute("foo", "bar")
}
8.外部配置 (Config.groovy)
grails.config.locations = [
"classpath:${appName}-config.properties",
"classpath:${appName}-config.groovy",
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy" ]
9.使用 System.properties 外部配置 (Config.groovy)
if (System.properties["${appName}.config.location"]) {
grails.config.locations << "file:" +
System.properties["${appName}.config.location"]
}
然后 -DmyApp.config.location=/path/to/myconfig.groovy
10.解决Windows下Grails启动时控制台显示乱码问题
grails -Dfile.encoding=GBK run-app
11.指定Grails启动时端口
grails -Dserver.port=9090 run-app