1

我想在生产环境中使用外部属性文件进行数据库配置。我已经尝试了一些博客和堆栈溢出的解决方案,但它仅适用于开发环境。

grailsVersion=3.3.2
4

1 回答 1

0

首先在其中创建属性文件src/main/resources(如果资源目录不存在,则创建它)。

然后从中删除配置application.yml(如果不会,那么它将覆盖)。用Application.groovy这个加载文件:

def url = getClass().classLoader.getResource("myconfig.properties")
def confFile = new File(url.toURI())
Properties properties = new Properties()
confFile.withInputStream {
  properties.load(it)
}

environment.propertySources.addFirst(new PropertiesPropertySource("local.config.location", properties))
于 2018-02-27T12:06:41.257 回答