本文介绍了配置DataSource.groovy进行Grails转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Openshift上部署一个Grails应用程序。
我正在使用本地构建的战争文件部署应用程序。
现在,我在DataSource.groovy文件中使用rhc-app-show命令给出的url作为数据库配置。
每当我尝试使用Openshift(例如$ OPENSHIFT_MYSQL_DB_HOST)的环境变量时,它会崩溃。任何关于如何使用配置文件中的想法或指针?



谢谢。

解决方案

我没有使用OpenShift,但Google带领我进入了,其中显示这些环境变量:

  OPENSHIFT_MYSQL_DB_HOST 
OPENSHIFT_MYSQL_DB_PASSWORD
OPENSHIFT_MYSQL_DB_USERNAME
OPENSHIFT_MYSQL_DB_URL
OPENSHIFT_MYSQL_DB_PORT

所以看起来这样会起作用:



<$ pre $ String host = System.getenv('OPENSHIFT_MYSQL_DB_HOST')
String port = System.getenv('OPENSHIFT_MYSQL_DB_PORT')
String dbName = System.getenv('OPENSHIFT_APP_NAME')
url =jdbc:mysql:// $ host:$ port / $ dbName
username = System.getenv('OPENSHIFT_MYSQL_DB_USERNAME')
password = System.getenv('OPENSHIFT_MYSQL_DB_PASSWORD')

属性{
...
}

}

缺少的一点是数据库名称 - 这是你会有的可用?我不确定 OPENSHIFT_MYSQL_DB_URL 的格式,但看起来您可能只能使用 url =jdbc:$ {System.getenv ('OPENSHIFT_MYSQL_DB_URL')}


I'm trying to deploy a Grails application on Openshift.I'm deploying the app using a locally built war file. Right now, I am using the url given by the rhc-app-show command in the DataSource.groovy file for my Database configurations.Whenever I try with the environment variables of Openshift (eg. $OPENSHIFT_MYSQL_DB_HOST), it crashes. Any idea or pointers on how to use those in the config file?

Thanks.

解决方案

I haven't used OpenShift but Google led me to the FAQ which shows these environment variables:

OPENSHIFT_MYSQL_DB_HOST
OPENSHIFT_MYSQL_DB_PASSWORD
OPENSHIFT_MYSQL_DB_USERNAME
OPENSHIFT_MYSQL_DB_URL
OPENSHIFT_MYSQL_DB_PORT

so it looks like this would work:

production {
   dataSource {
      driverClassName = 'com.mysql.jdbc.Driver'
      dialect = org.hibernate.dialect.MySQL5InnoDBDialect

      String host = System.getenv('OPENSHIFT_MYSQL_DB_HOST')
      String port = System.getenv('OPENSHIFT_MYSQL_DB_PORT')
      String dbName = System.getenv('OPENSHIFT_APP_NAME')
      url = "jdbc:mysql://$host:$port/$dbName"
      username = System.getenv('OPENSHIFT_MYSQL_DB_USERNAME')
      password = System.getenv('OPENSHIFT_MYSQL_DB_PASSWORD')

      properties {
         ...
      }
   }
}

The missing bit is the database name - is that something that you would have available? I'm not sure of the format of OPENSHIFT_MYSQL_DB_URL but it looks like you might just be able to use url = "jdbc:${System.getenv('OPENSHIFT_MYSQL_DB_URL')}"

这篇关于配置DataSource.groovy进行Grails转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 14:12