我设置了我的开发环境来查找包含用户名和密码的环境变量,这些变量是由开发人员在运行之前创建的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.
*
**********************************************************************/
这有点麻烦,但是将密码从我们的源代码和修订控制系统中排除是值得的。