【问题标题】:Dynamic Quartz Configuration in Grails 3Grails 3 中的动态 Quartz 配置
【发布时间】:2017-12-02 07:28:02
【问题描述】:

在 Grails 2 中,我们的 Config.groovy 文件中有以下代码块。 ConfigurationManagement 类在配置管理数据库中执行运行时查找以确定 quartz.autoStartup 参数应该是 true 还是 false。我们还使用类似的配置来加载额外的 Quartz 属性。

quartz {
    def autoStartupOnTheseServers = ConfigurationManagement.getValue("myApp.quartz.autoStartupOnTheseServers", "").split(",")

    if ( autoStartupOnTheseServers.any { it.trim().toUpperCase() == hostName.toUpperCase() } ) {
        autoStartup = true
    }
    else {
        autoStartup = false
    }

    // Default for clustering (jdbcStore) has to be "false" so the app will run locally.
    // Clustering (jdbcStore) will be true for DEV, TEST, QA, and PROD (set by Configuartion Management).
    jdbcStore = ConfigurationManagement.getValue("myApp.quartz.jdbcStore", "false").toBoolean()
    // don't set the props if not enabling quartz clustering...causes an exception.
    if(jdbcStore == true) { props(quartzProps) }
}

在 Grails 3 中,application.groovy 中使用的类似代码不起作用,并且我找不到任何用于 application.yml 的条件的工具。 Grails 3 中是否有任何方法可以进行类似的动态配置?

【问题讨论】:

    标签: grails quartz-scheduler grails-3.0


    【解决方案1】:

    在 Grails 3 中,您似乎无法直接设置这些值,但您可以声明一个局部变量并使用它来设置属性。因此,对于我上面的示例,以下工作:

    def extServerList = ConfigurationManagement.getValue("myApp.quartz.autoStartupOnTheseServers", "").split(",")
    def extAutoStartup = extServerList.any { it.trim().toUpperCase() == hostName.toUpperCase() } 
    def extJdbcStore = ConfigurationManagement.getValue("myApp.quartz.jdbcStore", "false").toBoolean()
    
    quartz {
        autoStartupOnTheseServers = extServerList
        autoStartup = extAutoStartup
        jdbcStore = extJdbcStore
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-07
      • 2016-06-27
      • 2014-01-18
      • 1970-01-01
      • 2020-07-08
      • 1970-01-01
      • 2017-01-15
      • 2016-03-14
      • 2016-07-04
      相关资源
      最近更新 更多