在Grails中得配置文件放在conf文件下,当系统启动时候会默认读取Config.groovy等配置文件。
在Config.groovy中除过几个仅从key就可以看出作用的key,value键值或者script外,Grails还提供了如下几个可配置选项:
Grails also provides the following configuration options:
grails.config.locations
- The location of properties files or addition Grails Config files that should be merged with main configuration grails.enable.native2ascii
- Set this to false if you do not require native2ascii conversion of Grails i18n properties files grails.views.default.codec
- Sets the default encoding regime for GSPs - can be one of 'none', 'html', or 'base64' (default: 'none'). To reduce risk of XSS attacks, set this to 'html'. grails.views.gsp.encoding
- The file encoding used for GSP source files (default is 'utf-8') grails.mime.file.extensions
- Whether to use the file extension to dictate the mime type in Content Negotiation grails.mime.types
- A map of supported mime types used for Content Negotiation grails.serverURL
- A string specifying the server URL portion of absolute links, including server name e.g. grails.serverURL="http://my.yourportal.com". See createLink . 1、grails.config.locations,这个选项可以让程序员自定义的*.properties文件或者*.groovy文件在系统启动后加载到主配置文件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"]
if(System.properties["${appName}.config.location"]) {
grails.config.locations << "file:" + System.properties["${appName}.config.location"]
}
模板的配置说明:
grailsApplication.config.自定义key来读取配置的值.如果用file配置的话,必须把自定义配置文件放置在${userHome}/.grails/,也就是c:\用户名\.grails这个文件夹下才可以被读取,同样可以用和上面一样的方式读取配置.
2、grails.enable.native2ascii这个主要是用来自动转换properties文件内容的,如果你不用国际化支持的话,可以在配置文件中设置为false
3、grails.views.default.codec是设置GSP编码方式的,有三个值可选,分别是:'none','html','base64',默认是none,设置为base64可以降低被XSS攻击的风险
4、grails.views.gsp.encoding是设置GSP默认编码,默认是utf-8
5、配置log日志:
用Log4j
log4j = { error 'org.codehaus.groovy.grails.web.servlet', // controllers 'org.codehaus.groovy.grails.web.pages' // GSP warn 'org.mortbay.log' }