In a Spring file I have:
<bean id="propertyConfigurer" class="org.myapp.MyConfigurator">
<property name="locations">
<list>
<value>classpath:configuration-${env}.properties</value>
</list>
</property>
</bean>
the ${env} variable is defined in maven's profile. But when I run from eclipse the application in tomcat 6 (published) it doesn't look in maven. So how can I set the variable for Tomcat?
Thanks
Randomize
在Eclipse中添加系统变量:转到Run - > Run Configurations - > Tomcat Select Arguments选项卡并添加到VM参数-Denv=blabla
要在tomcat context.xml
中定义可在spring中使用的变量,请将此行添加到context.xml
的右侧上下文中。
<Parameter name="env" value="ABCDEFG" override="false"/>
Tarlog solution can be solve your problem but only inside eclipse, if you remove your server definition from eclipse you lost the definition and you need to add it again each time you change your IDE or delete the server definition.
So better way create a shell or bat file(like runServer.sh/.bat) according to your environment and add this parameter to the JAVA_OPTS variable so this variable called when catalina.sh/.bat is running (startup.sh/.bat called catalina script inside it). You can use this approach at your local, test and prod environment.
Windows: runServer.bat
set JAVA_OPTS="-Dvariable=value"
tomcat/bin/startup.bat
Linux: runServer.sh
export JAVA_OPTS="-Dvariable=value"
tomcat/bin/startup.sh
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.