`
qxd8304
  • 浏览: 14848 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Grails中Config.groovy

阅读更多

在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"]
 }

模板的配置说明:

  • 可以配置多个自定义配置文件,用","隔开.
  • 可以用classpath和file两种方式定义配置文件位置,如果用classpath配置的话,通过实验得出,必须把自定义配置文件放置在conf文件下,这样程序在启动后就可以用
    grailsApplication.config.自定义key
     来读取配置的值.如果用file配置的话,必须把自定义配置文件放置在${userHome}/.grails/,也就是c:\用户名\.grails这个文件夹下才可以被读取,同样可以用和上面一样的方式读取配置.
  • 至于第三种if方式还没弄懂,呵呵.

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' }
 

 

 

 

 

 

 

 

 

 

分享到:
评论
1 楼 fighterhou 2012-04-13  
多谢,grails.config.locations比官方文档描述详细多了

相关推荐

Global site tag (gtag.js) - Google Analytics