Load environment-specific properties for use with PropertyPlaceholderConfigurer?

后端 未结 8 1126
夕颜
夕颜 2020-12-23 17:24

This seems like a pretty common problem, but I haven\'t found any sort of consensus on the best method, so I\'m posing the question here.

I\'m working on a command-l

相关标签:
8条回答
  • 2020-12-23 17:54

    The way I've normally done this in the past is to perform a substitution of the environment (dev/test/prod) in some sort of way at package/deployment time.

    That can either copy the correct config file to the right location on the server or just bundle the correct config file in the deployment package. If you use Ant/Maven this should be fairly straightforward to achieve. Which build tool are you using? Ant/Maven, that should provide you with the ability to substitute a value.

    Another alternative, which use PropertyPlaceholderConfigurer is that of the SYSTEM_PROPERTIES_MODE_OVERRIDE property. You can use this to set the location of the properties file you wish to load through a system property, see:

    http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.html#SYSTEM_PROPERTIES_MODE_OVERRIDE

    Hope that helps.

    0 讨论(0)
  • 2020-12-23 17:57

    I use the classpath option and adjust the classpath per environment in Jetty. In the jetty-maven-plugin you can set a directory for testclasses and have your testresources located there.

    For non-local environments (test / production) I use an environment flag and send the appropriate files to the $JETTY_HOME/resources folder (which is built into Jetty's classpath)

    0 讨论(0)
提交回复
热议问题