Grails中的外部属性文件3 [英] External properties file in grails 3

查看:96
本文介绍了Grails中的外部属性文件3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.properties]

grails.config.locations = ["classpath:config.properties"]

在config.groovy ,但这个文件在grails 3中不存在。

In the config.groovy, but this file do not exists in grails 3.

您有任何想法解决吗?

Have you any idea for solve?

推荐答案

由于Grails 3构建于Spring Boot之上,因此可以使用Spring Boot机制来实现外部化属性。即,使用 spring.config.location 命令行参数或 SPRING_BOOT_LOCATION 环境变量。 下面是它的Spring文档页面

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.

这篇关于Grails中的外部属性文件3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆