Grails配置:包括另一个配置文件 [英] Grails Config: include another config file

查看:166
本文介绍了Grails配置:包括另一个配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的主配置像:



grails.config.locations = [文件:grails-app / config / Jawr.groovy]。 / p>

当使用grails run-app运行应用程序时,一切正常。



战争档案)这不工作了,因为文件Jawr.groovy不再保存在文件系统(它应该只在战争)。



您有解决方案吗?您是否将外部文件包含在grails主配置文件中?



谢谢。

解决方案

好的,这里有几件事。



首先,因为你的配置路径上没有前导斜杠,知道在哪里。我在Tomcat中使用它,并且该路径相对于您在启动Tomcat服务器时所在的工作目录。如果您启动Tomcat,关闭它,更改目录,然后再次启动它,您将获得两个不同的配置路径。



其次,grails-app目录存在于您的Grails项目的源代码树中。解压缩的WAR文件的结构更像是Grails源代码树的web应用程序文件夹,包含诸如WEB-INF,META-INF,js,images等文件夹。



第三,你可能想避免将外部化的配置文件放在webapp的文件夹中。下次部署应用程序时,该配置将被旧版本的应用程序擦除。外部化配置的一个要点是,您可以重新部署而不必重新配置。



一个简单但不太理想的解决方案是使用静态,完全限定路径,如 /etc/yourApp/conf.groovy ,然后将其放在文档中。还有一个插件可以处理此问题。



http://www.grails.org/plugin/external-config



我没有使用它,但它的描述使它的声音喜欢它做明智的事情。


I have in my main config something like:

grails.config.locations = ["file:grails-app/config/Jawr.groovy"].

When running the application with grails run-app, everything is OK.

But, on deployment (creating the war archive) this does not work anymore, as the file "Jawr.groovy" is not kept anymore on the filesystem (it should be only in the war).

Do you have a solution for that? Hw do you include external files into the grails main configuration file?

Thanks.

解决方案

Okay, a few things here.

First, because you don't have a leading slash on your config path, that is a path relative to who knows where. I played with this in Tomcat, and that path ends up being relative to the working directory you were in when starting the Tomcat server. If you start Tomcat, shut it down, change directories, then start it again, you are going to get two different config paths.

Second, the grails-app directory only exists within the source tree of your Grails project. The structure of an unpacked WAR file is more like the web-app folder of your Grails source tree, with folders like WEB-INF, META-INF, js, images, etc.

Third, you probably want to avoid putting your externalized config file inside the folder of your webapp. The next time you deploy your app, that configuration is going to get wiped away with the old version of the app. One of the points of the externalized config is so that you can redeploy without having to reconfigure.

A simple, but less than ideal, solution would be to use a static, fully qualified path, like /etc/yourApp/conf.groovy, then put that in the documentation. There is also a plug-in that handles this.

http://www.grails.org/plugin/external-config

I haven't used it, but the description makes it sound like it does sensible things.

这篇关于Grails配置:包括另一个配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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