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

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值