LoginSignup
0
0

More than 5 years have passed since last update.

番外編:grails.config.locationsの設定

Last updated at Posted at 2016-04-19

環境

grails 2.3.11
groovy 2.1
GGTS3.6.4

grails.config.locationsとは

メイン設定にマージされるべきプロパティファイルや追加のGrails設定ファイルの場所である。

初期に生成されるConfig.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"]

${appName}-config.groovyと書いてあったので、.classでなく.groovyでないと 読み込めないと
思いこんでしまい、Tomcatのwarデプロイ時にうまくいかなかったが、普通 に.classを読み込んだのでメモ。

以下ソース

grails.config.locations
if (Metadata.getCurrent().isWarDeployed()){

    //log.warn 'warデプロイ'

    def path = getClass().getProtectionDomain().getCodeSource().getLocation()
    .getFile().replace(getClass().getSimpleName() + ".class", "").substring(1);

    grails.config.locations = ["file:" + path + "add-config.class"]

}else{

//log.warn 'eclipse起動'

grails.config.locations = ["file:buildターゲットフォルダ名/classes/add-config.class"]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0