0
我已经设置环境变量是这样的:外在的Grails配置成多个属性文件从环境变量
APP_HOME = "c:\app\app-datasource.properties
Config.groovy中我做
def ENV_NAME = "APP_HOME"
if(!grails.config.location || !(grails.config.location instanceof List)) {
grails.config.location = []
}
if(System.getenv(ENV_NAME)) {
println "Including configuration file specified in environment: " + System.getenv(ENV_NAME);
grails.config.location << "file:" + System.getenv(ENV_NAME)
} else if(System.getProperty(ENV_NAME)) {
println "Including configuration file specified on command line: " + System.getProperty(ENV_NAME);
grails.config.location << "file:" + System.getProperty(ENV_NAME)
} else {
println "No external configuration file defined."
}
我得到这个从岗位网上,我想知道我们是否需要使用grails.config.location
或grails.config.locations
? 而不是APP_HOME
被直接设置为属性文件,我可以将它设置为一个目录路径(e.g.: c:\apps)
,然后我可以有多个属性文件放在该目录中,然后如果我做了以下多次将它的工作吗?:
grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-datasource.properties"
grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-reporting.properties"
and so on...
在此先感谢
谢谢你的提示埃德,我要试试这个,其他的一件事是Grails的已预定义的设置从阅读../$ { appname} -config.properties与datasource.groovy相关的属性(就像我使用密码编解码器,所以我在数据源中使用codec.decode(“encrypted passwd”),我如何在属性文件中执行此操作),甚至标签由grails定义,如dataSource.username,dataSource.driverClassName等。我如何定制或添加一些在run-app中读取并在dataSource.groovy中使用的属性? – 2012-03-26 16:56:54
如果您查看原始'Config.grooy'文件的顶部,您将看到它在关于如何执行该操作的注释中提供了一些建议。您可能必须按照我在链接到的帖子中所做的将您的文件编码到'scripts/Events.groovy'中。我不知道dataSource.groovy问题的答案;我只是用我自己的替换默认的'DataSource.groovy'。我认为在部署应用程序时,您会想要使用JNDI数据源,这不需要您在war文件中存储密码。 – 2012-03-26 17:12:56