Spring datasource configuration for localhost, development, and production

前端 未结 6 913
暖寄归人
暖寄归人 2021-02-02 00:53

I\'m trying to figure out how my Spring app can determine where it is deployed and load the appropriate datasource. We have 3 environments...my local, the development server, a

6条回答
  •  孤街浪徒
    2021-02-02 01:31

    The other answers here have good ideas in them, but I'm answering because my own approach is something of a combination of the three. First, don't reference properties files of multiple environments directly in your Spring XML. Just work from a single file. Then, using a combination of Spring's , , , and SpEL, you can easily set up a very flexible configuration.

    1. The gets wired with the output of the .
    2. The uses SpEL to check for a system property with a given name. If available, it uses that as the location of a properties file to load. If not,
    3. Fall back to the , which tries to do a JDNI lookup for the location. If that also doesn't find anything, then
    4. Default to a hard-coded classpath location given by the default-value attribute of .

    This setup makes it simple to specify a properties file location no matter what environment you're in because of all the options.

提交回复
热议问题