【问题标题】:Injecting developer specific settings in Grails在 Grails 中注入开发人员特定的设置
【发布时间】:2013-03-24 07:35:58
【问题描述】:

现在我们的 grails 应用程序的 conf 中有一个 DataSource.groovy 文件。它有这样的设置......

   development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8"
            username = "user"
            password = "password"
        }
    }

当不同的开发人员将为其数据库使用不同的主机/用户名/密码时,在不更改此文件并尝试记住不签入对源代码管理的更改的情况下交换每个开发人员的设置的好方法是什么?随着应用程序的增长,需要在不同开发人员的机器上更改的设置数量也会增加。

【问题讨论】:

  • 我同意@doelleri。将设置外部化并将其置于源代码管理范围之外。
  • 新武藏在上面doelleri贴出的问题中的回答是最好的办法

标签: grails configuration


【解决方案1】:

我设置了我的开发环境来查找包含用户名和密码的环境变量,它们是由开发人员在运行grails run-app 之前创建的。

    development {
        dataSource {
          //dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:oracle:thin:@myserver:1521:SID"
            username = System.env.grails_user
            password = System.env.grails_password
            dialect = org.hibernate.dialect.OracleDialect
        }
    }

为了防止混淆,我把下面的注释块放在文件的开头(我们在 Windows 中开发)。

/***********************************************************************
 * The development and test environments expect to find the database
 * username and password in the following system environment variables.
 *
 *   grails_user
 *   grails_password
 *
 * Before trying grails run-app or grails test, be sure to set the
 * variables.  In Windows, you can type the following.
 *
 *   set grails_user=<your username>
 *   set grails_password=<your password>
 *   grails run-app
 *
 * The system will remember the password as long as you don't close the
 * cmd window.
 *
 **********************************************************************/

这有点麻烦,但在我们的源代码和修订控制系统中保留密码是值得的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2011-05-31
    • 2011-01-02
    • 2011-12-20
    • 2023-04-04
    相关资源
    最近更新 更多