gpt4 book ai didi

Grails 3 PluginDescriptor 配置

转载 作者:行者123 更新时间:2023-12-02 15:03:28 25 4
gpt4 key购买 nike

我正在将现有的 Grails 2.5.6 项目转换为 Grails 3.3.11。

对于我现有的应用程序(Grails 2.5.6),插件描述符的代码如下:

def doWithApplicationContext = { applicationContext ->
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])
}

此代码适用于早期版本的 grails。但是在我升级到 grails 3.3.11 之后,它会抛出异常: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
这是在行:
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])
查看 key 的类型,即 config.property.key 后,类型显示为 org.grails.config.NavigableMap$NullSafeNavigator .

旧版本是 LinkedHashMap。
property.key 在/grails-app/conf/application.groovy 下的 application.groovy 上设置得很好 property.key = [:]
我也尝试过设置类型 property.keyjava.util.HashMap 外部的插件描述符中.但似乎没有采用新的类型。

我在这里做错了什么?

最佳答案

而不是尝试通过以下方式动态执行此操作:

def doWithApplicationContext = { applicationContext ->
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(2, [controller: "results", action: "showData", templatePath: "/results/data"])
}

您可以在 grails-app/conf/plugin.yml 中定义这些值。像这样:
---
property:
key:
'2':
controller: results
action: showData
templatePath: '/results/data`

编辑

问题已经改变,以上内容不再有效。

而不是这样做:
def config = applicationContext.grailsApplication.config
def key = config.property.key
key.put(Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"])

您可以将其简化为:
config.merge([property: [key: [Constants.RESULT_CONST, [controller: "results", action: "showData", templatePath: "/results/data"]]]])

关于Grails 3 PluginDescriptor 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60887352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com