看起來通過grails.config.locations添加的任何選項在Config.groovy中不可用。 「$ {System.getProperty('password')}」。toString()是這個工作的唯一方法。 這裏是我的測試結果:
添加在Config.groovy中的開頭:
if (new File("${userHome}/.grails/${appName}-config.groovy").exists()){
grails.config.locations = ["file:${userHome}/.grails/${appName}-config.groovy"]
}
添加在Config.groovy中結束:的user.home /的
println "(*) grails.config.locations = ${grails.config.locations}"
def f = new File("${userHome}/.grails/${appName}-config.groovy")
f.eachLine{ line -> println line }
println "test password: ${testPassword}" // same result ([:]) with grails.config.testPassword
println "${System.getProperty('password')}"
grails.naming.entries = ['jdbc/test_mnr': [
type: "javax.sql.DataSource", //required
auth: "Container", // optional
description: "Data source for ...",
url: "jdbc:oracle:thin:@server:1521:SID",
username: "username",
password: "${System.getProperty('password')}".toString(),
driverClassName: "oracle.jdbc.driver.OracleDriver",
maxActive: "8",
maxIdle: "4",
removeAbandoned: "true",
removeAbandonedTimeout: "60",
testOnBorrow: "true",
logAbandoned: "true",
factory: "org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory",
validationQuery: "select count(*) from dual",
maxWait: "-1"
]
]
內容。 grails/mnroad-config.groovy:
testPassword='some_password'
以下是使用-Dpassword = somePas劍:
(*) grails.config.locations = [file:C:\Documents and Settings\carr1den/.grails/mnroad-config.groovy]
testPassword=some_password
test password: [:]
somePassword
grailsApplication.config.testPassword選項在應用程序初始化後可用。