我不知道您使用的是哪个版本的Tomcat,但是在Tomcat
7的catalina.sh文件中,您可以指定变量CATALINA_OPTS,该变量将传递给jvm。
但是也许设置环境变量并不是实现目标的最佳方法。也许最好是创建单独的“
app.properties”文件,并将其包含在applicationContext中,如下所示:
<context:property-placeholder location="classpath*:app.properties" />
以及catalina.sh的解决方案
# CATALINA_OPTS (Optional) Java runtime options used when the "start",# "run" or "debug" command is executed.# Include here and not in JAVA_OPTS all options, that should# only be used by Tomcat itself, not by the stop process,# the version command etc.# Examples are heap size, GC logging, JMX ports etc.
例:
CATALINA_OPTS =“-Dfolder = Dev”
编辑:
对于Windows,它应该类似于
set CATALINA_OPTS="-Dfolder=Dev"
编辑:
在Spring配置中,您可以像${propertyname}一样使用系统属性,还可以包含具有属性定义的文件,和
context:property-placeholder,并且该文件中定义的所有属性也可以在config中使用。
例如,您具有基本集属性:config.properties,以及具有数据库连接设置的文件集(DEV.properties,UAT.properties,PROD.properties)。那么,如何为不同的环境包括不同的属性?它可以通过多种方式完成,例如,在catalina.bat中设置系统属性
set CATALINA_OPTS="-Dbuild=DEV"
并在applicationConfig.xml中
<context:property-placeholder location="classpath*:${build}.properties, classpath*:config.properties" />或者,您可以创建不同的构建配置,并在最终的WAR中仅包含每个构建配置的一个属性(DEV,UAT,PROD)。在applicationConfig中设置类似以下内容:
<context:property-placeholder location="classpath*:*.properties" />



