grails与外部配置文件战争tomcat [英] grails war tomcat with external config file
问题描述
我想添加外部配置数据。因此,我在主 Config.groovy
文件中添加了以下行。
我导出了环境变量
DASH_CONFIG =< path_to_external_configfile> /extConfig.properties
-
extConfig.properties
simpleBSMDash.default .serverName =test.it.com
simpleBSMDash.default.refreshInterval =5
-
Config.groovy
if(System.getenv('DASH_CONFIG')){
println( 包括配置文件:+ System.getenv('DASH_CONFIG'));
grails.config.locations = [
classpath:exthConfig.properties,
file:./ extConfig.properties,
file:$ {System.getenv 'DASH_CONFIG')}]
} else {
println没有定义外部配置文件。
}
-
Bootstrap.groovy
我在Boostrap.groovy中初始化了一些配置参数。例如
import org.codehaus.groovy.grails.commons.ConfigurationHolder
新的AdminSettings(
refreshInterval:$ {ConfigurationHolder.config.simpleBSMDash.default.refreshInterval},serverName:$ {ConfigurationHolder.config.simpleBSMDash.default.serverName})。save(failOnError:true)
通过以下方式在本地运行应用程序时: grails -Denv = DEV run-app
。一切正常,AdminSettings实例被创建并使用期望的值初始化。
当我在tomcat服务器上部署war文件时,AdminSettings实例未被证明。然而,我没有导出环境变量
DASH_CONFIG =< path_to_external_configfile> /extConfig.properties。
我将 extConfig.properties
文件在 $ TOMCAT_HOME / lib
文件夹中,它没有工作。
我将它重命名为 extConfig.groovy
,它也没有帮助。
我通过stackflow搜索,但没有找到正确的答案。 >
有没有人有想法?
/ p>
在conf / Config.groovy中:
grails.config.locations = [
classpath:$ {appName} .properties,
file:$ {userHome} /。grails / $ {appName} -config.properties
]
它适用于Windows,尽管Groovy / Windows认为是家(〜)的地方可能有点令人惊讶。您尝试从Config.groovy访问环境变量看起来有点危险......
I want to add external config data. So I added in the main Config.groovy
file the following line.
I exported the environment variable
DASH_CONFIG=<path_to_external_configfile>/extConfig.properties
extConfig.properties
simpleBSMDash.default.serverName = "test.it.com" simpleBSMDash.default.refreshInterval = "5"
Config.groovy
if(System.getenv('DASH_CONFIG')) { println( "Including configuration file: " + System.getenv('DASH_CONFIG')); grails.config.locations = [ "classpath:exthConfig.properties", "file:./extConfig.properties", "file:${System.getenv('DASH_CONFIG')}"] } else { println "No external configuration file defined." }
Bootstrap.groovy
I'm initialisation some config parameter in Boostrap.groovy. for example
import org.codehaus.groovy.grails.commons.ConfigurationHolder new AdminSettings( refreshInterval:"${ConfigurationHolder.config.simpleBSMDash.default.refreshInterval}", serverName:"${ConfigurationHolder.config.simpleBSMDash.default.serverName}").save(failOnError:true)
When running locally the app through: grails -Denv=DEV run-app
. Everything works fine, the intance AdminSettings is created and initialised with the expected values.
When I deployed the war file on my tomcat server, the intance AdminSettings is not intantiated. Yet I did export environment variable
DASH_CONFIG=<path_to_external_configfile>/extConfig.properties.
I event put the extConfig.properties
file in $TOMCAT_HOME/lib
folder, it did not work as well.
I rename it to extConfig.groovy
, it did not help either.
I search through stackflow but did not find out a correct answer.
Does anyone have an idea?
Here's what works for us:
In conf/Config.groovy:
grails.config.locations = [
"classpath:${appName}.properties",
"file:${userHome}/.grails/${appName}-config.properties"
]
It works in Windows, though the places Groovy/Windows thinks is home (~) can be a bit surprising. Your attempt to access an environment variable from Config.groovy looks a bit risky...
这篇关于grails与外部配置文件战争tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!