【问题标题】:Grails config file closure definitionGrails 配置文件闭包定义
【发布时间】:2014-04-29 11:02:33
【问题描述】:

我正在为要定义重定向模式的 grails 应用程序编写配置文件。 我写了一个配置脚本 RedirectMappingsConfig.groovy:

import java.util.regex.Pattern

def c = {pattern, goto, path ->
    if (pattern instanceof Pattern && pattern.matcher(path).matches()) {
        return goto
    }
    return false
}

def redirectFromTo = [
        c.curry(Pattern.compile('/si/reference.*'), '/enterprise-solutions/references-and-partners#references'),
        c.curry(Pattern.compile('/si/kontakt.*'), '/contact-us'),
        c.curry(Pattern.compile('/si/zaposlitve.*'), '/careers'),
        c.curry(Pattern.compile('/aa'), '/')
]

此列表将在过滤器中读取,如果某些模式与请求 uri 匹配,该过滤器将执行重定向。

问题:应用程序无法编译,错误是:

Compilation error: startup failed:
RedirectMappingsConfig.groovy: 3: unexpected token: pattern @ line 3, column 10.
   def c = {pattern, goto, path ->
            ^

知道语法有什么问题吗? 我正在使用 grails 2.1.1。

【问题讨论】:

    标签: grails groovy closures


    【解决方案1】:

    goto 是 Groovy 中的 reserved word... 将闭包更改为:

    def c = {pattern, addr, path ->
        if (pattern instanceof Pattern && pattern.matcher(path).matches()) {
            return addr
        }
        return false
    }
    

    这个错误应该会消失 :-)

    【讨论】:

    • Tnx。该错误消息根本没有帮助。我认为该模式是保留字,而不是查看 goto。是时候喝杯咖啡舒展一下了。
    猜你喜欢
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 2014-03-14
    • 2014-07-20
    • 2012-01-11
    • 2015-01-27
    • 1970-01-01
    相关资源
    最近更新 更多