【问题标题】:Grails 2.4.4 - How to store config variable at war phase and get it in a Tomcat env?Grails 2.4.4 - 如何在战争阶段存储配置变量并将其放入 Tomcat 环境中?
【发布时间】:2018-12-08 07:33:40
【问题描述】:

当从 Grails 运行“war”命令时,我想存储构建提交以便之后在 GSP 中使用它。

在我的 Config.groovy 中

def proc = 'git rev-parse HEAD'.execute() proc.waitFor() build_commit.number = proc.in.text

在我的普惠制中

<p>${grailsApplication.config.build_commit.number}</p>

当我使用“运行应用程序”命令运行我的应用程序时一切正常,但是当我在 Tomcat 上部署我的 War 时,信息不再可用。

是不是因为 Config.groovy 在部署战争时重新评估?

我还尝试以编程方式编写对 application.properties 的构建提交,但我找不到这样做的方法.. 如果可能的话,我还需要知道如何检测 Tomcat 环境以避免重写空白值。

任何帮助将不胜感激。

【问题讨论】:

    标签: grails config grails-2.4 application.properties


    【解决方案1】:

    如果您需要持久性数据(例如您的 build_commit.number),您应该研究将您的应用程序与数据库集成,或者将其写入文件系统上的文件。任何一个都需要从您的开发环境(运行“运行应用程序”的地方)和生产环境(将战争部署到 tomcat 的地方)访问。

    【讨论】:

    • 将此信息存储到数据库对我来说不是解决方案。我可以将它写入一个文件,但似乎当调用 Config.groovy 时我无法使用 classLoader 来检索我的文件。我在我的 grails 项目的 conf 文件夹中创建了一个文件并尝试使用:this.class.classLoader.getResource('build_commit.txt')
    猜你喜欢
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多