External properties file in grails 3

前端 未结 6 1288
猫巷女王i
猫巷女王i 2021-02-08 00:32

I need read configuration from a external file properties in grails 3. In grails 2.x I link the file with:

grails.config.locations = [\"classpath:config.propert         


        
6条回答
  •  灰色年华
    2021-02-08 00:54

    Because Grails 3 is built on Spring Boot, you can use the Spring Boot mechanisms for externalized properties. Namely, using the spring.config.location command line parameter, or the SPRING_BOOT_LOCATION environment variable. Here's the Spring documentation page on it.

    The example the documentation provides for the command line parameter is this:

    $ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
    

    The way I have been using it is by setting an environment variable, like this:

    export SPRING_CONFIG_LOCATION="/home/user/application-name/application.yml"
    

    One of the nice features is that you can leave some properties in the properties file that is bundled in the app, but if there are some properties you do not want to include (such as passwords), those can be set specifically in the external config file.

提交回复
热议问题