2

现在我们的 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"
        }
    }

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

4

1 回答 1

2

我设置了我的开发环境来查找包含用户名和密码的环境变量,这些变量是由开发人员在运行之前创建的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.
 *
 **********************************************************************/

这有点麻烦,但是将密码从我们的源代码和修订控制系统中排除是值得的。

于 2013-04-02T20:54:04.657 回答